|
@@ -0,0 +1,67 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+from openerp import models, fields, api
|
|
|
+from openerp.tools.translate import _
|
|
|
+
|
|
|
+
|
|
|
+class sale_order(models.Model):
|
|
|
+ _name = "sale.order"
|
|
|
+ _description = "Sales Order"
|
|
|
+ _inherit = "sale.order"
|
|
|
+ _order = "date_order desc, name desc"
|
|
|
+
|
|
|
+ amount_untaxed = fields.Float(compute='_compute_amount_all')
|
|
|
+ amount_tax = fields.Float(compute='_compute_amount_all')
|
|
|
+ amount_total = fields.Float(compute='_compute_amount_all')
|
|
|
+
|
|
|
+ @api.depends('order_line.price_subtotal')
|
|
|
+ def _compute_amount_all(self):
|
|
|
+ for order in self:
|
|
|
+ amount_tax = amount_untaxed = 0.0
|
|
|
+ currency = order.pricelist_id.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
|
|
|
+ for line in order.order_line:
|
|
|
+ amount_untaxed += line.price_subtotal
|
|
|
+ amount_tax += self._amount_line_tax(line)
|
|
|
+ order.amount_tax = currency.round(amount_tax)
|
|
|
+ order.amount_untaxed = currency.round(amount_untaxed)
|
|
|
+ order.amount_total = currency.round(amount_tax + amount_untaxed)
|
|
|
+
|
|
|
+sale_order()
|
|
|
+
|
|
|
+
|
|
|
+class sale_order_line(models.Model):
|
|
|
+ _name = 'sale.order.line'
|
|
|
+ _inherit = 'sale.order.line'
|
|
|
+ _description = 'Order Line'
|
|
|
+
|
|
|
+ price_subtotal = fields.Float(compute='_compute_price_subtotal')
|
|
|
+
|
|
|
+ @api.depends('price_unit', 'product_uom_qty', 'product_uos_qty', 'discount')
|
|
|
+ def _compute_price_subtotal(self):
|
|
|
+ for line in self:
|
|
|
+ price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
|
|
|
+ taxes = line.tax_id.compute_all(price, line.product_uom_qty, line.product_id, line.order_id.partner_id)
|
|
|
+ currency = line.order_id.pricelist_id.currency_id.with_context(date=line.order_id.date_order or fields.Date.context_today(line.order_id))
|
|
|
+ line.price_subtotal = currency.round(taxes['total'])
|
|
|
+
|
|
|
+sale_order_line()
|
|
|
+
|