diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-05-20 05:23:26 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-05-20 05:23:26 +0700 |
| commit | be8056d1b69d4795724f164958171018d9968f46 (patch) | |
| tree | a4ca99ff3a20af18d618e7622fdd315afe543af1 | |
| parent | 17589184b8eaf942aba69a397c17f9bd233f69fe (diff) | |
<miqdad> set payment term readonly when on any approval process
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 40 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 15 |
2 files changed, 26 insertions, 29 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index bbd2cd71..c7e713d0 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -8,8 +8,6 @@ import pytz from io import BytesIO from collections import defaultdict -from psutil import users - _logger = logging.getLogger(__name__) @@ -334,9 +332,9 @@ class SaleOrder(models.Model): ('approve', 'Approve') ], tracking=True, string='State Cancel', copy=False) date_hold = fields.Datetime(string='Date Hold', tracking=True, readonly=True, help='Waktu ketika SO di Hold' - ) + ) date_unhold = fields.Datetime(string='Date Unhold', tracking=True, readonly=True, help='Waktu ketika SO di Unhold' - ) + ) def _compute_total_margin_excl_third_party(self): for order in self: @@ -389,7 +387,6 @@ class SaleOrder(models.Model): picking.do_unreserve() self.hold_outgoing = True self.date_hold = fields.Datetime.now() - def _validate_uniform_taxes(self): for order in self: @@ -407,8 +404,8 @@ class SaleOrder(models.Model): # if rec.fee_third_party == 0 and rec.total_margin_excl_third_party != rec.total_percent_margin: # # Gunakan direct SQL atau flag context untuk menghindari rekursi # self.env.cr.execute(""" - # UPDATE sale_order - # SET total_margin_excl_third_party = %s + # UPDATE sale_order + # SET total_margin_excl_third_party = %s # WHERE id = %s # """, (rec.total_percent_margin, rec.id)) # self.invalidate_cache() @@ -1155,23 +1152,12 @@ class SaleOrder(models.Model): helper_ids_str = self.env['ir.config_parameter'].sudo().get_param('sale.order.user_helper_ids') return helper_ids_str.split(', ') - def write(self, vals): - if 'carrier_id' in vals: - for picking in self.picking_ids: - if picking.state == 'assigned': - picking.carrier_id = self.carrier_id - - if 'payment_term_id' in vals: - if self.state not in ['cancel', 'draft'] and self.approval_status == 'approved': - if self.env.user.has_group('sales_team.group_sale_salesman') or self.env.user.has_group( - 'sales_team.group_sale_manager'): - raise UserError('Tidak bisa mengganti payment term karena sudah approved') - + def write(self, values): helper_ids = self._get_helper_ids() if str(self.env.user.id) in helper_ids: - vals['helper_by_id'] = self.env.user.id + values['helper_by_id'] = self.env.user.id - return super(SaleOrder, self).write(vals) + return super(SaleOrder, self).write(values) def check_due(self): """To show the due amount and warning stage""" @@ -1542,7 +1528,7 @@ class SaleOrder(models.Model): if not order.real_shipping_id: UserError('Real Delivery Address harus di isi') - + if not self.env.context.get('due_approve', []): if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', @@ -2023,3 +2009,13 @@ class SaleOrder(models.Model): if any(field in vals for field in ["order_line", "client_order_ref"]): self._calculate_etrts_date() return res + + def write(self, vals): + # Cek apakah payment_term_id diubah dan SO sedang dalam approval + if 'payment_term_id' in vals and any( + order.approval_status in ['pengajuan1', 'pengajuan2', 'approved'] for order in self): + raise UserError( + "Payment Term tidak dapat diubah karena Sales Order sedang dalam proses approval atau sudah diapprove.") + + # Lanjutkan dengan logika write yang sudah ada + return super(SaleOrder, self).write(vals) diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index a599a7b8..ad6bc11c 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -96,11 +96,11 @@ <attribute name="invisible">1</attribute> </field> <field name="user_id" position="after"> - <field name="hold_outgoing" readonly="1" /> - <field name="date_hold" readonly="1" widget="datetime" /> - <field name="date_unhold" readonly="1" widget="datetime" /> - <field name="helper_by_id" readonly="1" /> - <field name="compute_fullfillment" invisible="1" /> + <field name="hold_outgoing" readonly="1"/> + <field name="date_hold" readonly="1" widget="datetime"/> + <field name="date_unhold" readonly="1" widget="datetime"/> + <field name="helper_by_id" readonly="1"/> + <field name="compute_fullfillment" invisible="1"/> </field> <field name="tag_ids" position="after"> <field name="eta_date_start"/> @@ -303,8 +303,9 @@ </field> <field name="payment_term_id" position="attributes"> <attribute name="attrs"> - {'readonly': [('approval_status', '=', 'approved'), ('state', 'not in', - ['cancel', 'draft'])]} + {'readonly': ['|', ('approval_status', 'in', ['pengajuan1', 'pengajuan2', 'approved']), + ('state', 'not in', + ['cancel', 'draft'])]} </attribute> </field> |
