How to add owner's bank account ? ( Migration )

Hi. I would like to know, how can i add the owner in the model Bank\Bank accounts ?
I did do somthing like
ba = BankAccounts()
add_owner = ba.owners.new()
add_owner = Party.find([])[0]
…but that did not work , or:
add_owner.name ... or add_owner.code.. not at all. I noticed that it haves a strange label and ± signs on the right but i can’t figure it out how should i call it internally to trigger the options and send the party i need to bind with the right acc number… Thanks in advance :slight_smile:

The owners field is a Many2Many field. That means you have to fill it with a list of integers. Using Proteus you can do something like (I’m doing this off the top of my head, so anybody correct me if I’m wrong):

BankAccount = Model.get('bank.account')
Party = Model.get('party.party')

parties = Party.find([])

ba = BankAccount()
ba.owner = [p.id for p in parties]
ba.save()

Also see Tryton Scripting Client — tryton-proteus latest documentation and in particular how you can add categories. Just to mention, this is a very simple and probably won’t work because you have to fill more fields with data.

1 Like
to_save = []    
df = pandas.read_excel('banks.xlsx', dtype="str", engine="openpyxl")
    for i in range(len(df)):
        if sanitize(df['Name'][i]) and sanitize(df['Bankname'][i]) and sanitize(df['BIC'][i]):
             ba = BankAccount()
             ba.bank = Bank.find(['bic', '=', sanitize(df['BIC'][i])])[0]
             ba.currency = Currency.find(['code', '=', 'EUR'])[0]
             an = Party.find(['code', '=', 'C' + sanitize(df['Code'][i])], limit=1)
             ba_new_owner = ba.owners.new()
             ba_new_owner = [p.id for p in an][0] # passes as int
             ba_number = ba.numbers.new()
             ba_number.number = 'ES91 2100 0418 4502 0005 1332' # TEST IBAN ( valid Iban )
             num.type = 'other' # switch to 'iban' after validation and test.
             to_save.append(ba)
BankAccount.save(to_save)

First, thank you @edbo for your reply ! :slight_smile: I’ve tryed this…but still, it goes only with the code…and not selecting the first party witch i search by existing code, both in xlsx file and tryton… :thinking:

I find your code weird … :confused: I don’t get the ban = ba.owners.new() or the num = ba.numbers.new(). Again please take a look at the link I provided. You can get a clear picture out of it how to add data to the owners and number fields.

Just a wild guess: ba.owners = an or ba.owners.extend(an)

Thank you for your repIy ! I have made my code more clear. It really douse not matter how i name my variables… what i care more is to find out more methods, and the why’s behind, and also leave them here for further learning for someone else. The fact that i am not using the docs …is that i didn’t get it from the docs. Before asking for help i google, i read code, i try things and if none works… i get here and ask. So… if i use those .new() methods with fields numbers and owners it’s because it works…do not ask me why, because i didn’t get an explanaition from nobody, but it works for some cases. In the second case when adding the account numbers, works like magic. In the first case it dousen’t. If any can do explain as for starters i will apreciate it and many more readers after, i bet! :smiley:

to_save = []
df = pandas.read_excel('banks.xlsx', dtype="str", engine="openpyxl")
    for i in range(len(df)):
        if sanitize(df['Name'][i]) and sanitize(df['Bankname'][i]) and sanitize(df['BIC'][i]):
             ba = BankAccount()
             ba.bank = Bank.find(['bic', '=', sanitize(df['BIC'][i])])[0]
             ba.currency = Currency.find(['code', '=', 'EUR'])[0]
             own = Party.find(['code', '=', 'C' + sanitize(df['Code'][i])], limit=1)
             ba.owner = own
             ba_number = ba.numbers.new()
             ba_number.number = 'ES91 2100 0418 4502 0005 1332' # TEST IBAN ( valid Iban )
             ba_number.type = 'other' # switch to 'iban' after validation and test.
             to_save.append(ba)
BankAccount.save(to_save)

Play with the ba.owner = own to find the right one. It should be a List.

A bank account does not have an owner but a list of owners so the code should be:

ba.owners = [own]

Ahh typos :frowning_face: But the Party.find() is returning a List right? Even if it has a limit=1.

Yes it does so it should be:

own, = Party.find(['code', '=', 'C' + sanitize(df['Code'][i])], limit=1)

Hey guys! (@ced. @edbo ) Thank you for your patience. I have did the part of :

own, = Party.find(['code', '=', 'C' + sanitize(df['Codigo'][i])], limit=1)

it returns a class instance from what i know… and after

ba.owners = [own] witch converts it in to a list like this [proteus.Model.get(‘party.party’)(173)]

but that ...leaves to ".../lib/python3.6/site-packages/proteus/__init__.py", line 287, in __set__
    raise AttributeError
AttributeError

and if i try using the .new() method when i want to save a new owner, it saves only the code just as in the picture i’ve left before with the result. Really lost here… there is maybe another way to deal with this ? Or is it me that i do not understad completely how it works ? First time i did run it from the party.party side…but when i wanted to save the account bank numbers i could’nt…so i checked the bank.account and seemed that i can choose the owner directly from here, but still…can’t figure it out why dousent takes the owner as i am doing manually.

In proteus it is not possible to assing values on xxx2many fields. You should use append to add a single value or extend to include a list.

So this should work for you:

ba.owners.append(own)

Hope it helps!

1 Like

Thank you @pokoli! This is what i’ve been looking for! i did’nt even think of that ! :sweat: :clap: :clap:
Also, a big thanks for @edbo and @ced :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.