123456789101112131415161718192021222324252627282930313233343536 |
- # -*- coding: utf-8 -*-
- from openerp import api, fields, models
- from openerp.exceptions import except_orm
- class SaleOrder(models.Model):
- _inherit = 'sale.order'
- 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.model
- def join_sale_order_lines(self, values):
- self.env['sale.order.line'].search([('order_id','=',self.id)]).unlink()
- new_line = self.env['sale.order.line']
- for x in values:
- sale_order_line = ( {
- 'order_id': x['order_id'],
- 'product_id': x['product_id'],
- 'product_uom_qty': x['product_uom_qty'],
- 'product_uom': x['product_uos'],
- })
- new_line.create(sale_order_line)
- @api.depends('order_line.price_subtotal')
- def _compute_amount_all(self):
- for order in self:
- amount_tax = amount_untaxed = 0.0
- currency = order.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 += (line.product_uom_qty * line.price_unit) - line.price_subtotal
- order.amount_tax = currency.round(amount_tax)
- order.amount_untaxed = currency.round(amount_untaxed)
- order.amount_total = currency.round(amount_tax + amount_untaxed)
|