解决odoo 代码创建制造单无法完成,提示待生产的数量必须是正数

一般情况下,手动创建一条制造单 添加数据,点击保存。可以正常流转该单据。但是是通过后台代码,创建一条制造单(mrp.production)数据  再流转该制造订单时,完成该数据的时候,会提示 待生产的数量必须是正数 

 这是因为,在页面完成时,调用的是 button_mark_done 方法 该方法会将 制造单的product_qty

更改为 qty_produced 

def button_mark_done(self):
   ...
   for production in self:
        production.write({ 'date_finished': fields.Datetime.now(),
       'product_qty': production.qty_produced, 'priority': '0', 'is_locked': True, })

 如果此时是通过后台代码创建的数据,该qty_produced 为0,就会触发sql约束,product_qty的数值是必须大于0,就会提示待生产的数量必须是正数

    

_sql_constraints = [
    ('name_uniq', 'unique(name, company_id)', 'Reference must be unique per Company!'),
    ('qty_positive', 'check (product_qty > 0)', 'The quantity to produce must be positive!'),
]

qty_produced的数据记录逻辑是跟 moves_finished_values  字段有关的 在原生逻辑里面 制造订单添加产品 会动态触发_create_update_move_finished 方法 会添加moves_finished_values的数据

_create_update_move_finished 方法

def _create_update_move_finished(self):
    """ This is a helper function to support complexity of onchange logic for MOs.
    It is important that the special *2Many commands used here remain as long as     function
    is used within onchanges.
    """
    # keep manual entries
    list_move_finished = [(4, move.id) for move in self.move_finished_ids.filtered(
        lambda m: not m.byproduct_id and m.product_id != self.product_id)]
    list_move_finished = []
    moves_finished_values = self._get_moves_finished_values()
    moves_byproduct_dict = {move.byproduct_id.id: move for move in self.move_finished_ids.filtered(lambda m: m.byproduct_id)}
    move_finished = self.move_finished_ids.filtered(lambda m: m.product_id == self.product_id)
    for move_finished_values in moves_finished_values:
        if move_finished_values.get('byproduct_id') in moves_byproduct_dict:
            # update existing entries
            list_move_finished += [(1, moves_byproduct_dict[move_finished_values['byproduct_id']].id, move_finished_values)]
        elif move_finished_values.get('product_id') == self.product_id.id and move_finished:
            list_move_finished += [(1, move_finished.id, move_finished_values)]
        else:
            # add new entries
            list_move_finished += [(0, 0, move_finished_values)]
    self.move_finished_ids = list_move_finished

而如果通过代码创建的  制造单就不会 有moves_finished_values的数据  就会导致qty_produced的数值为0 所有 要想解决该问题,让制造单流转下去 就需要在创建制造单的时候,只能手动添加 move_finished_ids。这样就可以,成功的完成该订单。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值