# -*- encoding: utf-8 -*- from openerp import models, api, fields from pytz import timezone from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT from datetime import datetime,timedelta DATE_FORMAT = '%Y-%m-%d' class SalePurchaseDiscount(models.Model): _name = 'sale.purchase.discount' name = fields.Char('Nombre') value = fields.Float(string='Valor',default=0.0) type = fields.Selection([('sale','Ventas'),('purchase','Compras')],'Tipo de descuento') class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' _name = 'purchase.order.line' discount_id = fields.Many2one( 'sale.purchase.discount', string='Descuento', ondelete='restrict' ) @api.onchange('discount_id') def _calculate_purchase_discount(self): for line in self: line.discount = line.discount_id.value