summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-02-24 11:32:06 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-02-24 11:32:06 +0700
commit7df979b8d5312bb90d13d338f2a787dc35373f17 (patch)
tree12a5fd7b487781b52900505a2cffa999da692f9f /indoteknik_custom/models/sale_order.py
parenta9c4cd0c5ac694074f0e3a4359182a97f27f542e (diff)
parent38f8ddd9aaaad58c8d7ea27235cd109ba288693d (diff)
Merge branch 'odoo-production' into feature/integrasi_biteship
# Conflicts: # indoteknik_custom/models/__init__.py # indoteknik_custom/models/product_template.py # indoteknik_custom/models/sale_order.py # indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py77
1 files changed, 59 insertions, 18 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index c6f8adc4..d0b57a3d 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -28,11 +28,11 @@ class SaleOrder(models.Model):
shipping_cost_covered = fields.Selection([
('indoteknik', 'Indoteknik'),
('customer', 'Customer')
- ], string='Shipping Covered by', help='Siapa yang menanggung biaya ekspedisi?', copy=False)
+ ], string='Shipping Covered by', help='Siapa yang menanggung biaya ekspedisi?', copy=False, tracking=3)
shipping_paid_by = fields.Selection([
('indoteknik', 'Indoteknik'),
('customer', 'Customer')
- ], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False)
+ ], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False, tracking=3)
sales_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)])
have_outstanding_invoice = fields.Boolean('Have Outstanding Invoice', compute='_have_outstanding_invoice')
have_outstanding_picking = fields.Boolean('Have Outstanding Picking', compute='_have_outstanding_picking')
@@ -155,6 +155,15 @@ class SaleOrder(models.Model):
copy=False,
store=True
)
+ shipping_method_picking = fields.Char(string='Shipping Method Picking', compute='_compute_shipping_method_picking')
+
+ def _compute_shipping_method_picking(self):
+ for order in self:
+ if order.picking_ids:
+ carrier_names = order.picking_ids.mapped('carrier_id.name')
+ order.shipping_method_picking = ', '.join(filter(None, carrier_names))
+ else:
+ order.shipping_method_picking = False
@api.onchange('payment_status')
def _is_continue_transaction(self):
@@ -584,22 +593,22 @@ class SaleOrder(models.Model):
redirect_url = json.loads(lookup_json)['redirect_url']
self.payment_link_midtrans = str(redirect_url)
- # Generate QR code
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=10,
- border=4,
- )
- qr.add_data(redirect_url)
- qr.make(fit=True)
- img = qr.make_image(fill_color="black", back_color="white")
+ if 'redirect_url' in response:
+ qr = qrcode.QRCode(
+ version=1,
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
+ box_size=10,
+ border=4,
+ )
+ qr.add_data(redirect_url)
+ qr.make(fit=True)
+ img = qr.make_image(fill_color="black", back_color="white")
- buffer = BytesIO()
- img.save(buffer, format="PNG")
- qr_code_img = base64.b64encode(buffer.getvalue()).decode()
+ buffer = BytesIO()
+ img.save(buffer, format="PNG")
+ qr_code_img = base64.b64encode(buffer.getvalue()).decode()
- self.payment_qr_code = qr_code_img
+ self.payment_qr_code = qr_code_img
@api.model
def _generate_so_access_token(self, limit=50):
@@ -804,6 +813,7 @@ class SaleOrder(models.Model):
def sale_order_approve(self):
self.check_credit_limit()
+ self.check_limit_so_to_invoice()
if self.validate_different_vendor() and not self.vendor_approval:
return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor')
self.check_due()
@@ -862,6 +872,7 @@ class SaleOrder(models.Model):
return self._create_approval_notification('Pimpinan')
elif order._requires_approval_margin_manager():
self.check_credit_limit()
+ self.check_limit_so_to_invoice()
order.approval_status = 'pengajuan1'
return self._create_approval_notification('Sales Manager')
@@ -968,6 +979,29 @@ class SaleOrder(models.Model):
raise UserError(_("%s is in Blocking Stage, Remaining credit limit is %s, from %s and outstanding %s")
% (rec.partner_id.name, remaining_credit_limit, block_stage, outstanding_amount))
+ def check_limit_so_to_invoice(self):
+ for rec in self:
+ # Ambil jumlah outstanding_amount dan rec.amount_total sebagai current_total
+ outstanding_amount = rec.outstanding_amount
+ current_total = rec.amount_total + outstanding_amount
+
+ # Ambil blocking stage dari partner
+ block_stage = rec.partner_id.parent_id.blocking_stage if rec.partner_id.parent_id else rec.partner_id.blocking_stage or 0
+ is_cbd = rec.partner_id.parent_id.property_payment_term_id.id == 26 if rec.partner_id.parent_id else rec.partner_id.property_payment_term_id.id == 26 or False
+
+ # Ambil jumlah nilai dari SO yang invoice_status masih 'to invoice'
+ so_to_invoice = 0
+ for sale in rec.partner_id.sale_order_ids:
+ if sale.invoice_status == 'to invoice':
+ so_to_invoice = so_to_invoice + sale.amount_total
+ # Hitung remaining credit limit
+ remaining_credit_limit = block_stage - current_total - so_to_invoice
+
+ # Validasi limit
+ if remaining_credit_limit <= 0 and block_stage > 0 and not is_cbd:
+ raise UserError(_("The credit limit for %s will exceed the Blocking Stage if the Sale Order is confirmed. The remaining credit limit is %s, from %s and the outstanding amount is %s.")
+ % (rec.partner_id.name, block_stage - current_total, block_stage, outstanding_amount))
+
def validate_different_vendor(self):
if self.vendor_approval_id.filtered(lambda v: v.state == 'draft'):
draft_names = ", ".join(self.vendor_approval_id.filtered(lambda v: v.state == 'draft').mapped('number'))
@@ -1016,6 +1050,8 @@ class SaleOrder(models.Model):
def action_confirm(self):
for order in self:
+ order.check_credit_limit()
+ order.check_limit_so_to_invoice()
if self.validate_different_vendor() and not self.vendor_approval:
return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor')
@@ -1078,9 +1114,14 @@ class SaleOrder(models.Model):
if self.have_outstanding_invoice:
raise UserError("Invoice harus di Cancel dahulu")
+
+ disallow_states = ['draft', 'waiting', 'confirmed', 'assigned']
+ for picking in self.picking_ids:
+ if picking.state in disallow_states:
+ raise UserError("DO yang draft, waiting, confirmed, atau assigned harus di-cancel oleh Logistik")
for line in self.order_line:
if line.qty_delivered > 0:
- raise UserError("DO harus di-cancel terlebih dahulu.")
+ raise UserError("DO yang done harus di-Return oleh Logistik")
if not self.web_approval:
self.web_approval = 'company'
@@ -1124,7 +1165,7 @@ class SaleOrder(models.Model):
return False
def _requires_approval_margin_leader(self):
- return self.total_percent_margin <= 13 and not self.env.user.is_leader
+ return self.total_percent_margin < 15 and not self.env.user.is_leader
def _requires_approval_margin_manager(self):
return self.total_percent_margin <= 20 and not self.env.user.is_leader and not self.env.user.is_sales_manager