sale_order.py 1.2 KB

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