sale_order.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. from openerp.exceptions import except_orm
  4. class SaleOrder(models.Model):
  5. _inherit = 'sale.order'
  6. amount_untaxed = fields.Float( compute='_compute_amount_all')
  7. amount_tax = fields.Float( compute='_compute_amount_all')
  8. amount_total = fields.Float( compute='_compute_amount_all')
  9. @api.model
  10. def join_sale_lines(self, values):
  11. new_line = self.env['sale.order.line']
  12. sale_order_line = {
  13. 'product_id': values['product_id'],
  14. 'product_uom_qty': values['product_uom_qty'],
  15. 'order_id' : values['id']
  16. }
  17. new_line.create(sale_order_line)
  18. @api.depends('order_line.price_subtotal')
  19. def _compute_amount_all(self):
  20. for order in self:
  21. amount_tax = amount_untaxed = 0.0
  22. currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
  23. for line in order.order_line:
  24. amount_untaxed += line.price_subtotal
  25. amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
  26. order.amount_tax = currency.round(amount_tax)
  27. order.amount_untaxed = currency.round(amount_untaxed)
  28. order.amount_total = currency.round(amount_tax + amount_untaxed)