# Create account movements and account movements lines

**URL:** <https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307>\
**Category:** Developer\
**Created:** [September 30, 2020, 9:39am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307 "2020-09-30T09:39:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel\_dev](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/daniel_dev/32/975_2.png) [@daniel\_dev](https://discuss.tryton.org/u/daniel_dev)\
**Post date:** [September 30, 2020, 9:39am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/1 "2020-09-30T09:39:05Z")

</div>

Hi. I am tryng to write new account movements form a script, and the first part of fillling the form been easy, but to write new lines, i’ve seen that is allmost the same as in party , addresses, contact\_mechanism, by calling the .new() method. ( acclines = acc.lines.new() ) But when i’m tryng to use .find() over the the field named account to asign the account number from the search rezult i only receive AsssertionError on and on, even if i filter only the instances wich exist. It should receive the instance in accclines.account = rezult( instance), or it should be a string ? thing that this last one i doubt… here is my code..

```auto
        for i in range(len(df)): # Where df is a dataframe
            if not AccMoveLines.find(['account', '=', sanitize(df['CUENTA_AM'][i])], limit=1):
                acc = AccMove()
                acc.journal = AccJournal.find([('code', '=', 'APERTURA')])[0]
                acc.period = AccPeriod.find([('name', '=', '2020-01')])[0]
                rez = Account.find([('code', '=', sanitize(df['CUENTA_AM'][i]))], limit=1)
                acclines = acc.lines.new()
                if rez:
                   print(type(rez[0].code))
                to_save.append(acc)
            # print(acc.account, acc.journal.code, acc.period.name)
        AccMove.save(to_save)

```

The result is :  
100000000  
103000001  
103000002  
103000003  
103000004  
… Exactly the codes that i have in the excel file.  
And i understand that i should can do:  
acclines.account = rez # right ? or wrong ? Please help! 🙂  
also tryed to pass the : rez[0].code # same error..

```auto
    Traceback (most recent call last):
      File "migrate_account_move_lines.py", line 59, in <module>
        acclines.account = rez
      File "/home/user/tryton_server/venv_tryton/lib/python3.6/site-packages/proteus/ __init__.py", line 257, in __set__
        assert isinstance(value, (Model, type(None)))
    AssertionError

```

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [September 30, 2020, 10:47am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/2 "2020-09-30T10:47:00Z")

</div>

> [@daniel\_dev](#):
>
> `acclines.account = rez,`

You have a coma after the variable which contains the instance to a tuple.  
Removingt the coma should make it work.

---

<div class="post-metadata">

**Author:** ![daniel\_dev](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/daniel_dev/32/975_2.png) [@daniel\_dev](https://discuss.tryton.org/u/daniel_dev)\
**Post date:** [September 30, 2020, 11:06am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/3 "2020-09-30T11:06:29Z")

</div>

mmm..nope, that was just an error when i’ve edited this post. I did do:

```rez
    acclines = acc.lines.new()
    if rez:
       print(type(rez[0].code))
       acclines.account = rez

```

and what i get is the same error:  
100000000

```auto
    Traceback (most recent call last):
      File "migrate_account_move_lines.py", line 59, in <module>
        acclines.account = rez
      File "/home/user/tryton_server/venv_tryton/lib/python3.6/site-packages/proteus/ __init__.py", line 257, in __set__
        assert isinstance(value, (Model, type(None)))
    AssertionError

```

This is strange…i’m omitting somthing and i don’t know what exactly.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 30, 2020, 11:12am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/4 "2020-09-30T11:12:56Z")

</div>

> [@daniel\_dev](#):
>
> `acclines.account = rez`

`rez` is a list in your code, you can not assign a list of accounts to an account field.

---

<div class="post-metadata">

**Author:** ![daniel\_dev](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/daniel_dev/32/975_2.png) [@daniel\_dev](https://discuss.tryton.org/u/daniel_dev)\
**Post date:** [September 30, 2020, 11:28am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/5 "2020-09-30T11:28:10Z")

</div>

yep, you’re right..but then, i should pass an instance,and tryton should do the magic, right ? but i really don’t know how should i create it. 🤔 ill investigate and return here later..

If i pass the rez[0].code i get the same error.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 30, 2020, 11:29am UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/6 "2020-09-30T11:29:56Z")

</div>

Use an item of the list. Probably the first one as you always test this one.

---

<div class="post-metadata">

**Author:** ![daniel\_dev](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/daniel_dev/32/975_2.png) [@daniel\_dev](https://discuss.tryton.org/u/daniel_dev)\
**Post date:** [September 30, 2020, 1:53pm UTC](https://discuss.tryton.org/t/create-account-movements-and-account-movements-lines/3307/7 "2020-09-30T13:53:25Z")

</div>

Yep, that did worked.. I was going too far with the instance,but somehow now i see that not all the account codes exists in tryton, and if one of them returns None…

```
trytond.model.modelstorage.RequiredValidationError: A value is required for field "Account" in "Account Move Line". - 

```

and i can’t save the changes.

The thing is that i have account moves with acount move lines to save just by inserting  
account credit and debit  
and others with  
account party address( where this is automatically refilled ) credit and debit ..

```
 df = pandas.read_excel('file_name.xlsx', dtype="str", engine="openpyxl")
    for i in range(len(df)): # Where df is a dataframe
        if Account.find(['code', '=', sanitize(df['CUENTA_AM'][i])], limit=1):
            acc = AccMove()
            acc.journal = AccJournal.find([('code', '=', 'APERTURA')])[0]
            acc.period = AccPeriod.find([('name', '=', '2020-01')])[0]

            acclines = acc.lines.new()

            acc_code = Account.find([('code', '=', sanitize(df['CUENTA_AM'][i]))], limit=1)

            if acc_code:
                acclines.account = acc_code[0]
                acclines.credit = Decimal(0)
                acclines.debit = Decimal(0)

            acc_party_code = Party.find(['code', '=', sanitize(df['TERCERO'][i])], limit=1)
            if acc_party_code:
                acclines.account = acc_code[0]
                acclines.party = acc_party_code[0]
                acclines.credit = Decimal(0)
                acclines.debit = Decimal(0)
            print(acclines.account, acclines.party)

            to_save.append(acc)
    print(len(to_save))
    AccMove.save(to_save)

```

Didn’t find a solution yet. …

615  
Traceback (most recent call last):  
…  
…  
…  
File “/home/user/tryton\_server/venv\_tryton/lib/python3.6/site-packages/trytond-5.2.20-py3.6.egg/trytond/model/modelstorage.py”, line 1169, in required\_test  
\*\*cls. **names** (field\_name)))  
trytond.model.modelstorage.RequiredValidationError: A value is required for field “Party” in “Account Move Line”. -
