Skip to Content
Menu
This question has been flagged
3 Replies
2973 Views

I have created new one2many field like order lines in sale after other info tab. Also,I have created a new one2many field like invoice lines in invoice form after other info tab.

What i need to do is, I have to pass values from sale one2many field to invoice one2many field while clicking create invoice button.

I have tried inheriting _prepare_invoice and _prepare_invoice_line function in default. It does not work for other one2many field.

Could anyone please help me to do this!


Avatar
Discard
Best Answer

Please  submit your code here so the community can help you.
You can do it by inheriting _prepare_invoice as below:

Since you can create multiple invoices from one sale order you need to check if your field in invoice already has values to  not  move  them  each  time  you  create  invoice. 

def _prepare_invoice(self):
    self.ensure_one()
    res = return super([Your_Class_Name], self)._prepare_invoice()
    # Loop in your One2many field in sale order
    one2many_vals =[]
    for l in self.order_id.[Your_One2many]:
        one2many_vals.append(
        (0,0,{'One2many_column1_in_invoice_One2Many':l.[One2many_column1_in_sale_One2Many],
              'One2many_column2_in_invoice_One2Many':l.[One2many_column2_in_sale_One2Many],
              'One2many_column3_in_invoice_One2Many':l.[One2many_column3_in_sale_One2Many]
        }))
    res['One2many_field_name_in_invoice'] = one2many_vals
    return res


Avatar
Discard
Author

Thanks so much! It works well.

I'm very glad to hear that. Thanks

Best Answer

Please use _prepare_invoice method of sale.order. And should override this method in your custom module, in order to extend the invoice_vals dictionary, with something like:

class my_sale_order(osv.Model):
_inherit = "sale.order"
def _prepare_invoice(self, cr, uid, order, lines, context=None):
## Add your code here
my_sale_order()

Hope you know that odoo has optimized the invoice model. Now odoo has using account.move model for invoice and JE

Avatar
Discard
Best Answer

Hi,

If inheriting the default doesn't work in your case, then try to create a custom function, which creates as many lines you have in your  custom sale one2many to show or pass in the  custom invoice one2many. Then try calling the custom function in the create invoice button action.

Hope it helps,

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1485
1
Nov 24
1193
2
Sep 24
1047
1
Aug 24
2454
3
Aug 24
2687