odoo12 SO PO 订单行加入运费字段,计算小计和总计

        SO销售单和PO采购单,一定要在原始主类下添加字段,不能在继承类添加字段,不然xml识别不到字段。

SO销售单:

        添加express_price字段后,找到def _compute_amount(self):方法,最后两行加入小计和合计的计算逻辑:

    @api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id')
    def _compute_amount(self):
        """
        Compute the amounts of the SO line.
        """
        for line in self:
            price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
            taxes = line.tax_id.compute_all(price, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.order_id.partner_shipping_id)

            line.update({
                'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
                'price_total': taxes['total_included'],
                'price_subtotal': taxes['total_excluded'],
            })
            line.price_subtotal = line.product_uom_qty * line.price_unit + line.express_price
        line.price_subtotal = line.product_uom_qty * line.price_unit + line.express_price

PO采购单:

        由于PO采购单是SO销售单审核同步而来,所以运费字段取自SO销售单,同理,在主类创建计算字段,写入计算逻辑,最后再写入小计和合计逻辑。

express_price = fields.Float('运费', compute = '_coupute_express_price', store=True,inverse='_inverse_express_price')

    # 如果是SO源单据的采购单,审核时会填入运费
    @api.depends('order_id.order_line.product_id')
    def _coupute_express_price(self):
        if self.order_id.origin.startswith("SO"):
            a=self.env['sale.order'].search([('name','=',self.order_id.origin)])
            for b in a.order_line:
                if self.product_id == b.product_id:
                    self.express_price = b.express_price
    def _inverse_express_price(self):
        pass


    @api.depends('product_qty', 'price_unit', 'taxes_id')
    def _compute_amount(self):
        for line in self:
            vals = line._prepare_compute_all_values()
            taxes = line.taxes_id.compute_all(
                vals['price_unit'],
                vals['currency_id'],
                vals['product_qty'],
                vals['product'],
                vals['partner'])
            line.update({
                'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
                'price_total': taxes['total_included'],
                'price_subtotal': taxes['total_excluded'],
            })
            line.price_subtotal = line.product_qty * line.price_unit + line.express_price
        line.price_subtotal = line.product_qty * line.price_unit + line.express_price

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值