1

我在我的 odoo 环境中有一个多公司设置,我正在尝试制作一个模块,该模块允许将草稿发票移动到另一个可用的公司,但是在设置新的 company_id 时出现错误。我的代码:

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

错误:

 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.

关于如何实现这一目标的任何帮助或想法都会很棒。谢谢

4

1 回答 1

0

account.move 通过 finance_position_id 和 warehouse_id 字段与其他模型建立关系。

可能的解决方案:为财务头寸和仓库创建新记录,对于这些记录,您必须设置要放入 account.move 的公司。之后,在 account.move 模型中,您必须重新定义 write 方法:

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
于 2021-03-11T21:48:34.643 回答