sale_order.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. from openerp.exceptions import except_orm
  4. class SaleOrderInsert(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 sale_insert_lines_by_eiru_original(self, values):
  11. sale_lines_eiru = self.env['sale.order.line']
  12. lines = sale_lines_eiru.search([
  13. ('order_id', '=', values['id']),
  14. ('product_id', '=', values['product_id']),
  15. ])
  16. if len(lines) == 0:
  17. lines = {
  18. 'order_id' : values['id'],
  19. 'product_id': values['product_id'],
  20. }
  21. sale_lines_eiru.create(lines);
  22. if len(lines) == 1:
  23. lines.write({
  24. 'product_uom_qty': lines.product_uom_qty + 1,
  25. })
  26. @api.depends('order_line.price_subtotal')
  27. def _compute_amount_all(self):
  28. for order in self:
  29. amount_tax = amount_untaxed = 0.0
  30. currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
  31. for line in order.order_line:
  32. amount_untaxed += line.price_subtotal
  33. amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
  34. order.amount_tax = currency.round(amount_tax)
  35. order.amount_untaxed = currency.round(amount_untaxed)
  36. order.amount_total = currency.round(amount_tax + amount_untaxed)