如何从odoo采购行订单中获取价值到库存领料行?

2024-04-25 08:03:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我在库存移动模型上添加了分析账户字段,我需要在确认订单时,当库存移动行从采购订单行获取数量时,从采购订单行获取分析账户字段, 我该怎么做

 class StockMove(models.Model):
_inherit = "stock.move"

 analytic_account_id = fields.Many2one(string='Analytic Account',comodel_name='account.analytic.account',)

任何帮助都将不胜感激


Tags: 订单模型id数量movemodelmodelsstock
0条回答
网友
1楼 · 发布于 2024-04-25 08:03:47

重写_prepare_stock_moves方法,该方法为一个订单行准备库存移动数据,并返回准备在stock.move's create()中使用的字典列表

class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'

    @api.multi
    def _prepare_stock_moves(self, picking):
        res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
        res[0]['analytic_account_id'] = self.account_analytic_id.id
        return res 

要从采购订单中获取字段值,请使用反向_nameorder_id

res[0]['analytic_account_id'] = self.order_id.account_analytic_id.id

编辑:

要在生产订单上使用相同的逻辑,可以在将订单标记为已完成时设置帐户:

class ManufacturingOrder(models.Model):
    _inherit = 'mrp.production'

    analytic_account_id = fields.Many2one(string='Analytic Account', comodel_name='account.analytic.account')

    @api.multi
    def button_mark_done(self):           
        for order in self:
            for move in order.move_finished_ids:
                move.analytic_account_id = order.analytic_account_id
        res = super(ManufacturingOrder, self).button_mark_done()
        return res

相关问题 更多 >