Odoo 13 - Modify Journal Items when create Bill Vendor

647 views Asked by At

I have question about Vendor Bill.

When we create vendor bill, there is a journal items tab that the data will be generated when we choose Receipts.

I have requirement that user want to reformat the journal item, let say to add 1 account item of debit and credit.

Im looking the sourcode, and the journal items generated from this line :

moves_lines = self.env['stock.move'].browse([rec.id for rec in picking_ids.move_ids_without_package])
new_lines = self.env['account.move.line'] 
for line in moves_lines:
    new_line = new_lines.new(line._prepare_picking_account_move_line(self))
    #  if  i  comment  the  above  line,  the  journal  items  will  not  generate    

    new_line.account_id = new_line._get_computed_account()
    new_line.stock_move_id = line.id
    new_line._onchange_price_subtotal()
    new_lines += new_line

My questions are :

How can i modify the journal items account format ? If i comment the new_lines.new() it will not generate the journal items. But i don't know how to modify the journal items generation. For information the code is created by previous programmer but currently its not possible to contact them.

Thank you before

1

There are 1 answers

0
Levizar On

According to your piece of code, you "just" need to create a new account move line and add it to your record set (new_lines).

You will probably have to do it this way:

moves_lines = self.env['stock.move'].browse([rec.id for rec in picking_ids.move_ids_without_package])
new_lines = self.env['account.move.line'] 
for line in moves_lines:
    new_line = new_lines.new(line._prepare_picking_account_move_line(self))
    #  if  i  comment  the  above  line,  the  journal  items  will  not  generate    

    new_line.account_id = new_line._get_computed_account()
    new_line.stock_move_id = line.id
    new_line._onchange_price_subtotal()
    new_lines += new_line

# do your computation stuff here
dict_of_values = {
    debit: DEBIT_VALUE,
    credit: CREDIT_VALUE,
    account: ACCOUNT_ID,
    **any_other_required_values
}
new_account_move_line = self.env['account.move.line'].new(dict_of_values)
new_lines += new_account_move_line

Another way of doing that is to gather account_move_lines you want to create and to write them directly on your account_move.

amls_to_write = []
amls_to_write += [(0, 0, aml_dict_of_values)]
your_account_move.write({'line_ids': amls_to_write})

regarding the "cryptic" (0, 0, values), it corresponds to that: (ORM_METHOD_NUMBER, ID_OF_RECORD, VALUES_OF_RECORD) I let you have a look at the ORM methods: (don't forget to change the link for the version you are developing in) https://www.odoo.com/documentation/14.0/developer/reference/addons/orm.html#common-orm-methods

Note that the AccountMove model has a lot of constraint and that you have to balance the account_move_line together for the global balance of the account_move to be 0. (basic accounting stuff)

By the way, the variable names are highly unclear and there are rooms for confusion here. You should rename those to match what they are.

  • moves_lines and line are stock_move -> stock_moves and stock_move
  • new_lines and new_line are account_move_line -> account_move_lines and account_move_line (or aml if it's too long)