1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import datetime, timedelta
from pytz import timezone
class PurchasePricelist(models.Model):
_name = 'purchase.pricelist'
_rec_name = 'product_id'
name = fields.Char(string='Name', compute="_compute_name")
product_id = fields.Many2one('product.product', string="Product", required=True)
vendor_id = fields.Many2one('res.partner', string="Vendor", required=True)
product_price = fields.Float(string='Human Price', required=True)
system_price = fields.Float(string='System Price', required=True)
human_last_update = fields.Datetime(string='Human Update')
system_last_update = fields.Datetime(string='System Update')
@api.depends('product_id', 'vendor_id')
def _compute_name(self):
self.name = self.vendor_id.name + ', ' + self.product_id.name
@api.constrains('product_price','system_price','vendor_id','product_id')
def _contrains_product_price(self):
current_time = fields.Datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S')
update_by = self._context.get('update_by')
if update_by == 'system':
self.system_last_update = current_time
else:
self.human_last_update = current_time
|