summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-05-05 03:05:15 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-05-05 03:05:15 +0000
commitca48d2fcffbb48d6b3a09360144a71101f6f41ef (patch)
tree08769ff2dafb566042d8ecaaffff299c88aa699a
parent86cccc64c6f67b031a1bc345aae7922d83e021ea (diff)
parent6dcc5e48adb87d43101eaa2e868d12356da092be (diff)
Merged in reject_line_new (pull request #283)
<miqdad> Removed product from order line moved to reject line
-rwxr-xr-xindoteknik_custom/models/sale_order.py49
-rw-r--r--indoteknik_custom/models/sales_order_reject.py27
-rwxr-xr-xindoteknik_custom/views/sale_order.xml4
3 files changed, 78 insertions, 2 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index b0e17a3a..4c48684d 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -64,6 +64,55 @@ class ShippingOption(models.Model):
etd = fields.Char(string="Estimated Delivery Time")
sale_order_id = fields.Many2one('sale.order', string="Sale Order", ondelete="cascade")
+class SaleOrderLine(models.Model):
+ _inherit = 'sale.order.line'
+
+ def unlink(self):
+ lines_to_reject = []
+ for line in self:
+ if line.order_id:
+ now = fields.Datetime.now()
+
+ initial_reason="Product Rejected"
+
+ # Buat lognote untuk product yang di delete
+ log_note = (f"<li>Product '{line.product_id.name}' rejected. </li>"
+ f"<li>Quantity: {line.product_uom_qty}, </li>"
+ f"<li>Date: {now.strftime('%d-%m-%Y')}, </li>"
+ f"<li>Time: {now.strftime('%H:%M:%S')} </li>"
+ f"<li>Reason reject: {initial_reason} </li>")
+
+ lines_to_reject.append({
+ 'sale_order_id': line.order_id.id,
+ 'product_id': line.product_id.id,
+ 'qty_reject': line.product_uom_qty,
+ 'reason_reject': initial_reason, # pesan reason reject
+ 'message_body': log_note,
+ 'order_id': line.order_id,
+ })
+
+ # Call the original unlink method
+ result = super(SaleOrderLine, self).unlink()
+
+ # After deletion, create reject lines and post messages
+ SalesOrderReject = self.env['sales.order.reject']
+ for reject_data in lines_to_reject:
+ # Buat line baru di reject line
+ SalesOrderReject.create({
+ 'sale_order_id': reject_data['sale_order_id'],
+ 'product_id': reject_data['product_id'],
+ 'qty_reject': reject_data['qty_reject'],
+ 'reason_reject': reject_data['reason_reject'],
+ })
+
+ # Post to chatter with a more prominent message
+ reject_data['order_id'].message_post(
+ body=reject_data['message_body'],
+ author_id=self.env.user.partner_id.id, # menampilkan pesan di lognote sebagai current user
+ )
+
+ return result
+
class SaleOrder(models.Model):
_inherit = "sale.order"
diff --git a/indoteknik_custom/models/sales_order_reject.py b/indoteknik_custom/models/sales_order_reject.py
index 9983c64e..b180fad6 100644
--- a/indoteknik_custom/models/sales_order_reject.py
+++ b/indoteknik_custom/models/sales_order_reject.py
@@ -13,3 +13,30 @@ class SalesOrderReject(models.Model):
product_id = fields.Many2one('product.product', string='Product')
qty_reject = fields.Float(string='Qty')
reason_reject = fields.Char(string='Reason Reject')
+
+ def write(self, vals):
+ # Check if reason_reject is being updated
+ if 'reason_reject' in vals:
+ for record in self:
+ old_reason = record.reason_reject
+ new_reason = vals['reason_reject']
+
+ # Only post a message if the reason actually changed
+ if old_reason != new_reason:
+ now = fields.Datetime.now()
+
+ # Create the log note for the updated reason
+ log_note = (f"<li>Product '{record.product_id.name}' rejection reason updated:</li>"
+ f"<li>From: {old_reason}</li>"
+ f"<li>To: {new_reason}</li>"
+ f"<li>Updated on: {now.strftime('%d-%m-%Y')} at {now.strftime('%H:%M:%S')}</li>")
+
+ # Post ke lognote
+ if record.sale_order_id:
+ record.sale_order_id.message_post(
+ body=log_note,
+ author_id=self.env.user.partner_id.id,
+ )
+
+ # Call the original write method
+ return super(SalesOrderReject, self).write(vals) \ No newline at end of file
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 79a095fb..10c60e24 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -334,7 +334,7 @@
<field name="fulfillment_line_v2" readonly="1" />
</page>
<page string="Reject Line" name="page_sale_order_reject_line">
- <field name="reject_line" readonly="1" />
+ <field name="reject_line" readonly="0" />
</page>
<page string="Koli" name="page_sales_order_koli_line">
<field name="koli_lines" readonly="1" />
@@ -569,7 +569,7 @@
<tree editable="top" create="false">
<field name="product_id" readonly="1" />
<field name="qty_reject" readonly="1" />
- <field name="reason_reject" readonly="1" />
+ <field name="reason_reject" readonly="0" />
</tree>
</field>
</record>