I have added extra charge and deducted discount from subtotal in
sales order but I want to create invoice with deducted discount and
added surcharge amount in sales order. For eg. I have created a sales order with subtotal of 1550rs. and
less discount of 50 rs. and added surcharge of 100 rs. So I get the
total amount 1600 of sales order. I want invoice to be created with
total of 1600rs. after deducting discount and adding surcharge. here is code:- .py code:-
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 code:-
<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>
May I get any help on this?