扣除折扣并在发票

时间:2017-10-06 05:47:17

标签: python xml python-2.7 openerp odoo-10

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

例如。我创建了一个小计为1550rs的销售订单。减去50 rs的折扣。并增加了100卢比的附加费。所以我得到销售订单的总金额1600。我希望创建总计1600人的发票。扣除折扣后加上附加费。

我可以解决这个问题吗?

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>

0 个答案:

没有答案