1

I have a multi-company setup in my odoo environment and I am trying to make a module which alows a draft invoice to be moved to a different available company however when setting the new company_id I get an error. my code:

self.company_id = company_ids.filtered(lambda x: x.id != self.id)[0].id

error:

 Incompatible companies on records:
- 'S00007' belongs to company 'Sale Comp 1' and 'Fiscal Position' (fiscal_position_id: 'Some position') belongs to another company.
- 'S00007' belongs to company 'Sale Comp 1' and 'Warehouse' (warehouse_id: 'Sale Company 2') belongs to another company.

Any help or ideas on how to achieve this would be great. Thank you

1 Answers1

0

account.move has relations with other models through fiscal_position_id and warehouse_id fields.

Possible solution: Create new records for fiscal positions and for warehouse, and for those records you'll have to set the company that you want to put in your account.move. After that, in account.move model you'll have to redefine the write method:

def write(self, vals):
    if 'company_id' in vals:
        company = self.env['res.company].search([('id', '=', int(vals.get('company_id'))])
        vals['fiscal_position_id'] = YOUR_NEW_FISCAL_POSITION_ID
        vals['warehouse_id'] = YOUR_NEW_WAREHOUSE_ID
    res = super(AccountMove, self).write(vals)
    return res
southernegro
  • 384
  • 4
  • 20