purchase_order.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. from openerp.exceptions import except_orm
  4. from datetime import datetime
  5. DATE_FORMAT = '%Y-%m-%d'
  6. class PurchaseOrderInsert(models.Model):
  7. _inherit = 'purchase.order'
  8. # amount_untaxed = fields.Float( compute='_compute_amount_all')
  9. # amount_tax = fields.Float( compute='_compute_amount_all')
  10. # amount_total = fields.Float( compute='_compute_amount_all')
  11. @api.model
  12. def purchase_insert_lines_by_eiru_original(self, values):
  13. purchase_lines_eiru = self.env['purchase.order.line']
  14. lines = purchase_lines_eiru.search([
  15. ('order_id', '=', values['id']),
  16. ('product_id', '=', values['product_id']),
  17. ])
  18. if len(lines) == 0:
  19. lines = {
  20. 'order_id' : values['id'],
  21. 'name' : values['name'],
  22. 'product_id': values['product_id'],
  23. 'price_unit': values['price_unit'],
  24. 'date_planned': datetime.now().strftime(DATE_FORMAT)
  25. }
  26. purchase_lines_eiru.create(lines);
  27. if len(lines) == 1:
  28. lines.write({
  29. 'product_qty': lines.product_qty + 1,
  30. })
  31. # @api.depends('order_line.price_subtotal')
  32. # def _compute_amount_all(self):
  33. # for order in self:
  34. # amount_tax = amount_untaxed = 0.0
  35. # currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
  36. # for line in order.order_line:
  37. # amount_untaxed += line.price_subtotal
  38. # amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
  39. # order.amount_tax = currency.round(amount_tax)
  40. # order.amount_untaxed = currency.round(amount_untaxed)
  41. # order.amount_total = currency.round(amount_tax + amount_untaxed)