我是在股票移动模型上添加了分析帐户字段,我需要当股票移动线得到数量形式的PO线时,当我确认订单时,我如何才能得到分析帐户字段表格线?
class StockMove(models.Model):
_inherit = "stock.move"
analytic_account_id = fields.Many2one(string='Analytic Account',comodel_name='account.analytic.account',)如有任何帮助,将不胜感激。
发布于 2020-05-31 11:34:21
重写移动方法,该方法准备股票,为一个订单行移动数据,并返回准备在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 要从采购订单中获取字段值,请使用inverse_name order_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 reshttps://stackoverflow.com/questions/62115193
复制相似问题