sale_order.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_uos': x['product_uos'],
  19. })
  20. # print sale_order_line
  21. new_line.create(sale_order_line)
  22. @api.depends('order_line.price_subtotal')
  23. def _compute_amount_all(self):
  24. for order in self:
  25. amount_tax = amount_untaxed = 0.0
  26. currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
  27. for line in order.order_line:
  28. amount_untaxed += line.price_subtotal
  29. amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
  30. order.amount_tax = currency.round(amount_tax)
  31. order.amount_untaxed = currency.round(amount_untaxed)
  32. order.amount_total = currency.round(amount_tax + amount_untaxed)