sale_purchase_discount.py 900 B

1234567891011121314151617181920212223242526272829
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, api, fields
  3. from pytz import timezone
  4. from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
  5. from datetime import datetime,timedelta
  6. DATE_FORMAT = '%Y-%m-%d'
  7. class SalePurchaseDiscount(models.Model):
  8. _name = 'sale.purchase.discount'
  9. name = fields.Char('Nombre')
  10. value = fields.Float(string='Valor',default=0.0)
  11. type = fields.Selection([('sale','Ventas'),('purchase','Compras')],'Tipo de descuento')
  12. class PurchaseOrderLine(models.Model):
  13. _inherit = 'purchase.order.line'
  14. _name = 'purchase.order.line'
  15. discount_id = fields.Many2one(
  16. 'sale.purchase.discount',
  17. string='Descuento',
  18. ondelete='restrict'
  19. )
  20. @api.onchange('discount_id')
  21. def _calculate_purchase_discount(self):
  22. for line in self:
  23. line.discount = line.discount_id.value