purchase.py 763 B

12345678910111213141516171819
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields
  3. from datetime import date
  4. class account_invoice(models.Model):
  5. _inherit = 'account.invoice'
  6. def invoice_validate(self):
  7. res = super(account_invoice, self).invoice_validate()
  8. for item in self.invoice_line:
  9. product = self.env['product.product'].browse(item.product_id.id)
  10. if product:
  11. template = self.env['product.template'].browse(product.product_tmpl_id.id)
  12. if(template.price_change == 'purchase'):
  13. product.write({'standard_price': item.price_unit, 'last_purchase_date': date.today()})
  14. else:
  15. product.write({'last_purchase_date': date.today()})
  16. return res