Skip to Content
Menu
This question has been flagged
2715 Views

I create a custom field in account.invoice.line .

I added the field in account.invoice.tax

I override the prepare invoice function like this

def _prepare_tax_line_vals(self, line, tax):
    res = super(AccountInvoice, self)._prepare_tax_line_vals(line, tax)
    if not res.get('cost_center_id') and line.cost_center_id:
        res['cost_center_id'] = line.cost_center_id.id
    return res

I print the cost_center values here the value is printed here.

But in account.invoice.tax the values is not there. How to solve this issue??

Avatar
Discard

if 'cost_center_id' is Relational Field than you can not directly assign Value. You have to use below Operation with it.

In your case you need to use (0, 0, { values })

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write *values* on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Author

@Palkesh Baraiya:cost_center_id is the many2field.is many2one field need these operations?

I have the same problem, were you able to find a solution ?

Related Posts Replies Views Activity
2
Nov 24
25098
2
May 24
5524
3
Mar 24
4964
0
Mar 24
264
3
Feb 24
11421