diff options
Diffstat (limited to 'indoteknik_custom/models/purchase_pricelist.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index b7c3785a..67b22e4c 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -11,17 +11,19 @@ class PurchasePricelist(models.Model): 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) + system_price = fields.Float(string='System Price', readonly=True) human_last_update = fields.Datetime(string='Human Update') system_last_update = fields.Datetime(string='System Update') count_trx_po = fields.Integer(string='Count Trx Product') count_trx_po_vendor = fields.Integer(string='Count Trx Vendor') - + taxes_product_id = fields.Many2one('account.tax', string='Taxes Human', domain=[('type_tax_use', '=', 'purchase')]) + taxes_system_id = fields.Many2one('account.tax', string='Taxes System', readonly=True) + include_price = fields.Float(string='Final Price', readonly=True) @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') + @api.constrains('product_price','system_price','vendor_id','product_id','taxes_system_id','taxes_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') @@ -30,6 +32,41 @@ class PurchasePricelist(models.Model): else: self.human_last_update = current_time + @api.constrains('system_last_update','system_price','product_price','human_last_update','taxes_system_id','taxes_product_id') + def _contrains_include_price(self): + + price_unit, taxes = self._get_valid_price() + if price_unit == 0: + self.include_price = 0 + return + + tax_include = taxes.price_include + if taxes: + if tax_include: + price_unit = price_unit + else: + price_unit = price_unit + (price_unit * 11 / 100) + else: + price_unit = price_unit + (price_unit * 11 / 100) + + self.include_price = price_unit + + def _get_valid_price(self): + purchase_price = self + price = 0 + taxes = None + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if system_last_update > human_last_update: + price = purchase_price.system_price + taxes = purchase_price.taxes_system_id + else: + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id + + return price, taxes + @api.constrains('vendor_id', 'product_id') def _check_duplicate_purchase_pricelist(self): for price in self: @@ -39,8 +76,8 @@ class PurchasePricelist(models.Model): ] domain.append(('id', '!=', price.id)) - massage="Product dan vendor yang anda gunakan sudah ada di purchase pricelist" existing_purchase = self.search(domain, limit=1) + massage="Ada duplikat product dan vendor, berikut data yang anda duplikat : \n" + str(existing_purchase.product_id.name) + " - " + str(existing_purchase.vendor_id.name) + " - " + str(existing_purchase.product_price) if existing_purchase: raise UserError(massage)
\ No newline at end of file |
