# -*- coding: utf-8 -*- from openerp import api, fields, models from openerp.exceptions import except_orm from datetime import datetime DATE_FORMAT = '%Y-%m-%d' class PurchaseOrderInsert(models.Model): _inherit = 'purchase.order' # amount_untaxed = fields.Float( compute='_compute_amount_all') # amount_tax = fields.Float( compute='_compute_amount_all') # amount_total = fields.Float( compute='_compute_amount_all') @api.model def purchase_insert_lines_by_eiru_original(self, values): purchase_lines_eiru = self.env['purchase.order.line'] lines = purchase_lines_eiru.search([ ('order_id', '=', values['id']), ('product_id', '=', values['product_id']), ]) if len(lines) == 0: lines = { 'order_id' : values['id'], 'name' : values['name'], 'product_id': values['product_id'], 'price_unit': values['price_unit'], 'date_planned': datetime.now().strftime(DATE_FORMAT) } purchase_lines_eiru.create(lines); if len(lines) == 1: lines.write({ 'product_qty': lines.product_qty + 1, }) # @api.depends('order_line.price_subtotal') # def _compute_amount_all(self): # for order in self: # amount_tax = amount_untaxed = 0.0 # currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order)) # for line in order.order_line: # amount_untaxed += line.price_subtotal # amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal # order.amount_tax = currency.round(amount_tax) # order.amount_untaxed = currency.round(amount_untaxed) # order.amount_total = currency.round(amount_tax + amount_untaxed)