diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-09-29 13:20:20 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-09-29 13:20:20 +0700 |
| commit | 875b20796c7fa64abebe430b2707df597e29836b (patch) | |
| tree | 2521fbf09f4695253fd7db1ff7613b7f003f20ea /indoteknik_custom/models/purchase_order.py | |
| parent | 914bcd75dd2baddb2841cbfba6a64ebd453fecdb (diff) | |
| parent | ec21c4721f35028fc9b2a61bd0dbc6e4bf600e74 (diff) | |
Merge branch 'odoo-backup' into pum-v2
# Conflicts:
# indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 50913a80..b34ec926 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -6,6 +6,7 @@ import logging from pytz import timezone, utc import io import base64 +from odoo.tools import lazy_property try: from odoo.tools.misc import xlsxwriter except ImportError: @@ -66,7 +67,7 @@ class PurchaseOrder(models.Model): sale_order = fields.Char(string='Sale Order') matches_so = fields.Many2many('sale.order', string='Matches SO', compute='_compute_matches_so') is_create_uangmuka = fields.Boolean(string='Uang Muka?') - move_id = fields.Many2one('account.move', string='Journal Entries Uang Muka', domain=[('move_type', '=', 'entry')]) + move_id = fields.Many2one('account.move', string='Journal Entries Uang Muka', domain=[('move_type', '=', 'entry')], copy=False) logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') status_printed = fields.Selection([ ('not_printed', 'Belum Print'), @@ -115,6 +116,20 @@ class PurchaseOrder(models.Model): compute='_compute_complete_bu_in_count' ) + show_description = fields.Boolean( + string='Show Description', + default=True + ) + + @api.onchange('show_description') + def onchange_show_description(self): + if self.show_description == True: + for line in self.order_line: + line.show_description = True + else: + for line in self.order_line: + line.show_description = False + def _compute_complete_bu_in_count(self): for order in self: if order.state not in ['done', 'cancel']: @@ -137,7 +152,7 @@ class PurchaseOrder(models.Model): def _compute_date_planned(self): """ date_planned = the earliest date_planned across all order lines. """ for order in self: - order.date_planned = False + order.date_planned = order.date_planned @api.constrains('date_planned') def constrains_date_planned(self): @@ -183,8 +198,11 @@ class PurchaseOrder(models.Model): # Ambil semua BU awal dari PO base_bu = StockPicking.search([ + '|', + '&', ('name', 'ilike', 'BU/'), - ('origin', 'ilike', order.name) + ('group_id.id', '=', order.group_id.id), + ('origin', '=', order.name), ]) all_bu = base_bu @@ -214,10 +232,12 @@ class PurchaseOrder(models.Model): # Step 1: cari semua BU pertama (PUT, INT) yang berasal dari PO ini base_bu = StockPicking.search([ + '|', + '&', ('name', 'ilike', 'BU/'), - ('origin', 'ilike', self.name) + ('group_id.id', '=', self.group_id.id), + ('origin', '=', self.name), ]) - all_bu = base_bu seen_names = set(base_bu.mapped('name')) @@ -228,10 +248,10 @@ class PurchaseOrder(models.Model): ('origin', 'in', ['Return of %s' % name for name in seen_names]) ]) next_names = set(next_bu.mapped('name')) - + if not next_names - seen_names: break - + all_bu |= next_bu seen_names |= next_names @@ -1037,8 +1057,19 @@ class PurchaseOrder(models.Model): message="Produk "+line.product_id.name+" memiliki vendor berbeda dengan SO (Vendor PO: "+str(self.partner_id.name)+", Vendor SO: "+str(line.so_line_id.vendor_id.name)+")", sticky=True ) + + def _check_assets_note(self): + for order in self: + # Cari apakah ada line dengan produk ID 614469 ('Assets Mesin & Peralatan') + asset_line = order.order_line.filtered(lambda l: l.product_id.id == 595346) + if asset_line and not order.notes: + raise UserError(_( + "%s berisi produk 'Assets Mesin & Peralatan'. " + "Harap isi Notes untuk menjelaskan kebutuhan dan divisi terkait." + ) % order.name) def button_confirm(self): + self._check_assets_note() # self._check_payment_term() # check payment term res = super(PurchaseOrder, self).button_confirm() current_time = datetime.now() @@ -1066,8 +1097,11 @@ class PurchaseOrder(models.Model): # sticky=True # ) + has_bom = self.product_bom_id.id + has_manufacturing = self.manufacturing_id.id + if not self.from_apo: - if not self.matches_so and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: + if not self.matches_so and not self.env.user.is_purchasing_manager and not self.env.user.is_leader and not has_bom and not has_manufacturing: raise UserError("Tidak ada link dengan SO, harus di confirm oleh Purchasing Manager") send_email = False |
