Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    Mrp.py 中 action_confirm 的一个疑似bug

    Odoo 开发与实施交流
    3
    4
    2912
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • C
      ccdos 最后由 编辑

      晕 ,是我看错了.  谢谢 jeff
      上海-gavin 的跟帖很好 ,这帖子就留着吧

      ==============================
      今天读 mrp.py 的 action_confirm

      <br />&nbsp; &nbsp; def action_confirm(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot; Confirms production order.<br />&nbsp; &nbsp; &nbsp; &nbsp; @return: Newly generated Shipment Id.<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; shipment_id = False<br />&nbsp; &nbsp; &nbsp; &nbsp; wf_service = netsvc.LocalService(&quot;workflow&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; uncompute_ids = filter(lambda x:x, [not x.product_lines and x.id or False for x in self.browse(cr, uid, ids, context=context)])<br />&nbsp; &nbsp; &nbsp; &nbsp; self.action_compute(cr, uid, uncompute_ids, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; for production in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; produce_move_id = self._make_production_produce_line(cr, uid, production, context=context)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Take routing location as a Source Location.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_location_id = production.location_src_id.id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if production.bom_id.routing_id and production.bom_id.routing_id.location_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_location_id = production.bom_id.routing_id.location_id.id<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for line in production.product_lines:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; consume_move_id = self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  destination_location_id=source_location_id, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wf_service.trg_validate(uid, &#039;stock.picking&#039;, shipment_id, &#039;button_confirm&#039;, cr)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; production.write({&#039;state&#039;:&#039;confirmed&#039;}, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; return shipment_id<br />
      


      下面这句, 应该是创建一个 picking , 为 mo 领料.
          shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)


      我感觉应该 是为当前mo 创建 一个picking 即可, 不应该放在 循环内的.

            shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)

      而且  方法_make_production_internal_shipment 最后有一句 

      &nbsp; &nbsp; &nbsp; &nbsp; production.write({&#039;picking_id&#039;: picking_id}, context=context)<br />
      



      显然是将 picking 关联到了 mo .

      大牛们 看看, 是不是应该把
            shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)
      这行 放在 循环外面 ?

      1 条回复 最后回复 回复 引用 0
      • wjfonhand
        wjfonhand 最后由 编辑

        看错了?所在循环用于遍历MO啊,每个循环内确定一个生产订单,对应创建一个picking,我这边不觉得有问题啊。

        GoodERP -- Odoo China fork

        1 条回复 最后回复 回复 引用 0
        • W
          wang 最后由 编辑

          哈哈 我也重构过这块的代码!!我还是放在循环里面的 我_make

          _production_consume_line 方法被我返回成数组了

          <br />class mrp_fresh(osv.osv):<br />&nbsp; &nbsp; _inherit=&#039;mrp.production&#039;<br /><br />&nbsp; &nbsp; def _make_production_consume_line(self, cr, uid, production_line, parent_move_id, source_location_id=False, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; stock_move = self.pool.get(&#039;stock.move&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; production = production_line.production_id<br />&nbsp; &nbsp; &nbsp; &nbsp; # Internal shipment is created for Stockable and Consumer Products<br />&nbsp; &nbsp; &nbsp; &nbsp; if production_line.product_id.type not in (&#039;product&#039;, &#039;consu&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return False<br />&nbsp; &nbsp; &nbsp; &nbsp; destination_location_id = production.product_id.property_stock_production.id<br />&nbsp; &nbsp; &nbsp; &nbsp; if not source_location_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_location_id = production.location_src_id.id<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; #TODO 自动选择批次号 先入先出<br />&nbsp; &nbsp; &nbsp; &nbsp; production_lot = self.pool.get(&#039;stock.production.lot&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; #查询该商品所有的批次号信息,是根据批次号的排序查询<br />&nbsp; &nbsp; &nbsp; &nbsp; ids = production_lot.search(cr,uid,[(&#039;product_id&#039;,&#039;=&#039;,production_line.product_id.id)])<br />&nbsp; &nbsp; &nbsp; &nbsp; objects = production_lot.browse(cr,uid,ids)<br />&nbsp; &nbsp; &nbsp; &nbsp; temp_new = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; move_state = &#91;&#039;assigned&#039;,&#039;waiting&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; #需求要的数量<br />&nbsp; &nbsp; &nbsp; &nbsp; use_quantity = production_line.product_qty<br />&nbsp; &nbsp; &nbsp; &nbsp; #下面查找符合条件的批次号<br />&nbsp; &nbsp; &nbsp; &nbsp; for obj in objects:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prodlot_id = obj.id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #查询该批次号&nbsp; 的商品 所有的待生产&nbsp; 未投料的 数量<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.execute(&#039;select sum(product_qty) from stock_move where (state IN %s) and product_id =%s and prodlot_id =%s&#039;,(tuple(move_state),production_line.product_id.id,prodlot_id))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = cr.fetchone()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # 已有的生产单的在本批次号中 商品数量&nbsp; 和 本次要的数量 总和 <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #等待生产的数量 <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user_quantity = (res and res[0] and int(res[0])) or 0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #需求总量<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def_quantity = obj.stock_available - user_quantity <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if def_quantity &gt;=use_quantity:#如果需求的数量直接就被该批次满足了情况<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_new.append({&#039;prodlot_id&#039;:prodlot_id,&#039;quantity&#039;:use_quantity})<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else :<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_new.append({&#039;prodlot_id&#039;:prodlot_id,&#039;quantity&#039;:def_quantity})<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use_quantity -= def_quantity<br />&nbsp; &nbsp; &nbsp; &nbsp; move_ids = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; all_quantity = 0<br />&nbsp; &nbsp; &nbsp; &nbsp; for temp in temp_new:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; all_quantity+=int(temp&#91;&#039;quantity&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; if int(production_line.product_qty - all_quantity)&gt;0:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_new.append({&#039;prodlot_id&#039;:None,&#039;quantity&#039;:int(production_line.product_qty - all_quantity)})<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; for new in temp_new:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; move_id = stock_move.create(cr, uid, {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;: production.name,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;date&#039;: production.date_planned,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_id&#039;: production_line.product_id.id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&#039;product_qty&#039;: production_line.product_qty,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_qty&#039;: new&#91;&#039;quantity&#039;],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_uom&#039;: production_line.product_uom.id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_uos_qty&#039;: production_line.product_uos and production_line.product_uos_qty or False,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_uos&#039;: production_line.product_uos and production_line.product_uos.id or False,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;location_id&#039;: source_location_id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;location_dest_id&#039;: destination_location_id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;move_dest_id&#039;: parent_move_id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;state&#039;: &#039;waiting&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&#039;prodlot_id&#039;:prodlot_id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;prodlot_id&#039;:new&#91;&#039;prodlot_id&#039;],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;company_id&#039;: production.company_id.id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; production.write({&#039;move_lines&#039;: [(4, move_id)]}, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; move_ids.append(move_id)<br />&nbsp; &nbsp; &nbsp; &nbsp; return move_ids<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; def action_confirm(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot; Confirms production order.<br />&nbsp; &nbsp; &nbsp; &nbsp; @return: Newly generated Shipment Id.<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; shipment_id = False<br />&nbsp; &nbsp; &nbsp; &nbsp; wf_service = netsvc.LocalService(&quot;workflow&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; uncompute_ids = filter(lambda x:x, [not x.product_lines and x.id or False for x in self.browse(cr, uid, ids, context=context)])<br />&nbsp; &nbsp; &nbsp; &nbsp; self.action_compute(cr, uid, uncompute_ids, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; for production in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; produce_move_id = self._make_production_produce_line(cr, uid, production, context=context)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Take routing location as a Source Location.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_location_id = production.location_src_id.id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if production.bom_id.routing_id and production.bom_id.routing_id.location_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_location_id = production.bom_id.routing_id.location_id.id<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for line in production.product_lines:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; consume_move_ids = self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if shipment_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for consume_move_id in consume_move_ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  destination_location_id=source_location_id, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if shipment_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wf_service.trg_validate(uid, &#039;stock.picking&#039;, shipment_id, &#039;button_confirm&#039;, cr)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; production.write({&#039;state&#039;:&#039;confirmed&#039;}, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; return shipment_id<br /><br />
          
          1 条回复 最后回复 回复 引用 0
          • First post
            Last post