【发布时间】:2016-06-24 17:43:19
【问题描述】:
我在 REPAIR-ORDER 的订单行中添加了多个产品,显示了每个产品的价格 - 但未征税的小计和总显示 (0) 而不是所有产品的总和。
我附上了一些 MRP REPAIR (.py) 文件的代码:
def _amount_all_wrapper_repair(self, cr, uid, ids, field_name, arg, context=None):
""" Wrapper because of direct method passing as parameter for function fields """
return self._amount_all_repair(cr, uid, ids, field_name, arg, context=context)
def _amount_all_repair(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
'amount_tax': 0.0,
'amount_total': 0.0,
}
val = val1 = 0.0
cur = order.sale_id.pricelist_id.currency_id
for line in order.order_line_ids:
val1 += line.price_subtotal
val += self._amount_line_tax_repair(cr, uid, line, context=context)
res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
return res
mrp_repair.xml 的代码:
<group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
<field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<div class="oe_subtotal_footer_separator oe_inline">
<label for="amount_total" />
<button name="button_dummy"
states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
</div>
<field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<div class="oe_inline" groups="garage.group_display_margin">
<label for="margin" style="font-weight:bold;"/>
</div>
<field name="margin" nolabel="1" style="font-weight:bold;" groups="garage.group_display_margin"/>
</group>
编辑 - 添加信息
我发现如果没有下面的代码(此代码导致 MRP_REPAIR 将订单行添加到 REPAIR ORDER 和 SALES ORDER 中),添加一个价格不会在总字段中计算的产品,并显示零 (0)
elif this.repair_sale_order_line_id:
sale_obj = self.pool.get('sale.order')
so_vals = {
'partner_id' : this.repair_sale_order_line_id.partner_id.id,
'fleet_id': this.repair_sale_order_line_id.fleet_id.id,
'responsable_id': uid,
}
created_so_id = so_obj.create(cr, uid, so_vals, context=context)
sol_vals = {'order_id': created_so_id,
'price_unit': this.price_unit,
'product_uom_qty': this.product_uom_qty,
'price_subtotal': this.price_subtotal,
'discount': this.discount,
'product_id': this.product_id.id,
'tax_id': [(6, 0, [x.id for x
in this.tax_id])],
'name': this.name,
}
self.pool.get('mrp.repair').write(cr, uid, this.repair_sale_order_line_id.id, {'sale_id':created_so_id},context=context)
sol_id = sol_obj.create_sol(cr, uid, sol_vals, context)
super(repair_sale_order_line, self).write(cr, uid, [res],{'sale_order_line_id':sol_id})
似乎使用的是销售订单行而不是内部维修销售订单行。问题是:我怎样才能使 mrp 不依赖于 SO 或其 ORDER LINES。
【问题讨论】:
-
旧 API 函数字段仅在保存时计算。如果您想让它们像 on_change 字段一样计算,请添加一些 on_change 行为(这只会在视图中执行某些操作,因为无论如何这些字段都是在保存时计算的)或将字段更改为新的 API 计算字段(包括 on_change)。
-
检查页面顶部的编辑:谢谢
-
有什么办法可以解决这个问题?