Python 在发票中扣除折扣并增加额外费用

Python 在发票中扣除折扣并增加额外费用,python,xml,python-2.7,openerp,odoo-10,Python,Xml,Python 2.7,Openerp,Odoo 10,我已在销售订单小计中添加了额外费用和扣除折扣,但我想在销售订单中创建扣除折扣和增加附加费金额的发票 例如,我创建了一个小计为1550卢比的销售订单。再减去50卢比的折扣,再加上100卢比的附加费,我就得到了1600卢比的销售订单。我希望创建总计为1600R的发票。扣除折扣和附加费后 我能得到一些解决办法吗 class account_pet(models.Model): _inherit = "account.invoice" discount = fields.Integer("discou

我已在销售订单小计中添加了额外费用和扣除折扣,但我想在销售订单中创建扣除折扣和增加附加费金额的发票

例如,我创建了一个小计为1550卢比的销售订单。再减去50卢比的折扣,再加上100卢比的附加费,我就得到了1600卢比的销售订单。我希望创建总计为1600R的发票。扣除折扣和附加费后

我能得到一些解决办法吗

class account_pet(models.Model):
_inherit = "account.invoice"

discount = fields.Integer("discount")
surcharge = fields.Integer("surcharge")

@api.depends('amount_total')
def _prepare_invoice(self):
    for order in self:
        amount_untaxed = amount_tax = subtotal = total_amount =discount_amount = 0.0
        for line in order.order_line:
            amount_untaxed += line.price_subtotal
            amount_tax += line.price_tax
        subtotal = amount_untaxed + amount_tax + order.surcharge  # + order.shipping_amt
        if order.discount:
            discount_amount = subtotal - order.discount

        else:
            total_amount = discount_amount + amount_untaxed + amount_tax + order.surcharge 
        res = discount_amount + total_amount

        order.amount_total = res

    vals = {'discount': self.discount,
            'surcharge': self.surcharge,
            'total_amount':self.total.amount
            }
    return vals

class sale_order_pet(models.Model):
     _inherit = "sale.order"

     @api.depends('discount', 'surcharge')
     def _amount_all(self):

    for order in self:
        amount_untaxed = amount_tax = subtotal = total_amount =discount_amount = 0.0
        for line in order.order_line:
            amount_untaxed += line.price_subtotal
            amount_tax += line.price_tax
        subtotal = amount_untaxed + amount_tax + order.surcharge  # + order.shipping_amt
        if order.discount:
            discount_amount = subtotal - order.discount

        else:
            total_amount = discount_amount + amount_untaxed + amount_tax + order.surcharge  # + order.shipping_amt
        res = discount_amount + total_amount

        order.amount_total = res


discount = fields.Integer("Discount")
surcharge = fields.Integer("Surcharge")
.xml代码

<record model="ir.ui.view" id="custom_order_form">
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="name">Sale Order Pet Form</field>
        <field name="model">sale.order</field>
        <field name="arch" type="xml">

            <data>
                <xpath expr="//field[@name='amount_untaxed']" position="after">
                    <field name="discount"/>
                </xpath>

                <xpath expr="//field[@name='amount_untaxed']" position="after">
                    <field name="surcharge"/>
                </xpath>
        </data>
        </field>
    </record>



<record model="ir.ui.view" id="cust_order_form">
        <field name="inherit_id" ref="account.invoice_supplier_form"/>
        <field name="name">account Pet Form</field>
        <field name="model">account.invoice</field>
        <field name="arch" type="xml">

            <data>
                <xpath expr="//field[@name='amount_untaxed']" position="after">
                    <field name="discount"/>
                </xpath>

                <xpath expr="//field[@name='amount_untaxed']" position="after">
                    <field name="surcharge"/>
                </xpath>
            </data>
        </field>
    </record>

销售订单宠物表格
销售订单
帐户宠物表格
帐户、发票

到目前为止,您尝试了什么?发布你的代码!我已经添加了我的代码。如果我错了,请建议改正。到目前为止,你试过什么?发布你的代码!我已经添加了我的代码。如果我错了,请建议改正。