sale_order.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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_order_lines(self, values):
  11. self.env['sale.order.line'].search([('order_id','=',self.id)]).unlink()
  12. new_line = self.env['sale.order.line']
  13. for x in values:
  14. sale_order_line = ( {
  15. 'order_id': x['order_id'],
  16. 'product_id': x['product_id'],
  17. 'product_uom_qty': x['product_uom_qty'],
  18. 'product_uom': x['product_uos'],
  19. })
  20. new_line.create(sale_order_line)
  21. @api.depends('order_line.price_subtotal')
  22. def _compute_amount_all(self):
  23. for order in self:
  24. amount_tax = amount_untaxed = 0.0
  25. currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
  26. for line in order.order_line:
  27. amount_untaxed += line.price_subtotal
  28. amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
  29. order.amount_tax = currency.round(amount_tax)
  30. order.amount_untaxed = currency.round(amount_untaxed)
  31. order.amount_total = currency.round(amount_tax + amount_untaxed)