diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-08-18 14:02:52 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-08-18 14:02:52 +0700 |
| commit | a2cb7fefe587a215f5bebe52ee85ef7bf440df0a (patch) | |
| tree | 08d081e343232ea7d2a8498e000d6550f4c10b02 | |
| parent | 2a4daec248064f7dc1d9e5a9d08ad935a299ca61 (diff) | |
automatic purchase pricelist
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 29 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 20 | ||||
| -rw-r--r-- | indoteknik_custom/views/product_sla.xml | 14 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_pricelist.xml | 7 |
4 files changed, 58 insertions, 12 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 9e851ef9..c968ed53 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -2,6 +2,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from datetime import datetime, timedelta import logging +from pytz import timezone _logger = logging.getLogger(__name__) @@ -40,6 +41,31 @@ class PurchaseOrder(models.Model): count_line_product = fields.Float('Total Item', compute='compute_count_line_product') note_description = fields.Char(string='Note', help='bisa diisi sebagai informasi indent barang tertentu atau apapun') + def add_product_to_pricelist(self): + for line in self.order_line: + current_time = fields.Datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + + purchase_pricelist = self.env['purchase.pricelist'].search([ + ('product_id', '=', line.product_id.id), + ('vendor_id', '=', line.order_id.partner_id.id) + ]) + purchase_pricelist = purchase_pricelist.with_context(update_by='system') + if not purchase_pricelist: + purchase_pricelist.create([{ + 'vendor_id': line.order_id.partner_id.id, + 'product_id': line.product_id.id, + 'product_price': 0.00, + 'system_price': line.price_unit, + 'system_last_update': current_time, + }]) + return True + + for pricelist in purchase_pricelist: + pricelist.write({ + 'system_last_update': current_time, + 'system_price': line.price_unit + }) + def _compute_date_planned(self): for order in self: if order.date_approve: @@ -196,12 +222,15 @@ class PurchaseOrder(models.Model): for line in self.order_line: if not line.product_id.purchase_ok: raise UserError("Terdapat barang yang tidak bisa diproses") + if line.product_id: + self.add_product_to_pricelist() if line.price_unit != line.price_vendor: send_email = True break if send_email: self._send_mail() + self.approval_status = 'approved' self.po_status = 'menunggu' diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index 4ea2b9ef..419ca8e0 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -1,5 +1,7 @@ -from odoo import models, fields, api - +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' @@ -8,8 +10,20 @@ class PurchasePricelist(models.Model): 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='Price', 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 diff --git a/indoteknik_custom/views/product_sla.xml b/indoteknik_custom/views/product_sla.xml index cec3f980..d0d3f84a 100644 --- a/indoteknik_custom/views/product_sla.xml +++ b/indoteknik_custom/views/product_sla.xml @@ -18,15 +18,15 @@ <field name="arch" type="xml"> <form> <sheet string="Product Sla"> + <group> <group> - <group> - <field name="product_variant_id"/> - <field name="avg_leadtime"/> - <field name="sla"/> - <field name="version"/> - </group> + <field name="product_variant_id"/> + <field name="avg_leadtime"/> + <field name="sla"/> + <field name="version"/> </group> - </sheet> + </group> + </sheet> </form> </field> </record> diff --git a/indoteknik_custom/views/purchase_pricelist.xml b/indoteknik_custom/views/purchase_pricelist.xml index d6abcec1..f9fd52ba 100755 --- a/indoteknik_custom/views/purchase_pricelist.xml +++ b/indoteknik_custom/views/purchase_pricelist.xml @@ -8,6 +8,9 @@ <field name="product_id"/> <field name="vendor_id"/> <field name="product_price"/> + <field name="system_price"/> + <field name="human_last_update"/> + <field name="system_last_update"/> </tree> </field> </record> @@ -15,7 +18,7 @@ <record id="purchase_pricelist_form" model="ir.ui.view"> <field name="name">purchase.pricelist.form</field> <field name="model">purchase.pricelist</field> - <field name="arch" type="xml"> + <field name="arch" type="xml"> <form> <sheet> <group> @@ -23,8 +26,8 @@ <field name="product_id"/> <field name="vendor_id" context="{'res_partner_search_mode': 'supplier'}"/> <field name="product_price"/> + <field name="system_price"/> </group> - <group></group> </group> </sheet> </form> |
