summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2026-01-20 15:57:31 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2026-01-20 15:57:31 +0700
commitc48a2248a874277b7795d86c6247f51430c0b810 (patch)
treedfa9540bbc72bcbdbc54844e97c1a47788cbeefb
parentd2268706824167cd23dd3ea9e22acc241bc35122 (diff)
push
-rw-r--r--fixco_custom/models/account_move.py5
-rw-r--r--fixco_custom/models/account_move_reversal.py4
-rwxr-xr-xfixco_custom/models/sale.py25
-rw-r--r--fixco_custom/views/account_move.xml3
-rwxr-xr-xfixco_custom/views/sale_order.xml3
5 files changed, 38 insertions, 2 deletions
diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py
index 2346fec..6315b6e 100644
--- a/fixco_custom/models/account_move.py
+++ b/fixco_custom/models/account_move.py
@@ -47,6 +47,11 @@ class AccountMove(models.Model):
compute="_compute_need_refund",
help="Flag otomatis kalau invoice sudah paid dan picking terkait di-return."
)
+ total_discount = fields.Monetary(
+ string='Total Discount',
+ related='sale_id.total_discount',
+ currency_field='currency_id',
+ )
# purchase_item_ids= fields.Many2many(
# 'purchase.order.line',
# string='Auto Complete (PO Item)',
diff --git a/fixco_custom/models/account_move_reversal.py b/fixco_custom/models/account_move_reversal.py
index 745346a..c3cc5cf 100644
--- a/fixco_custom/models/account_move_reversal.py
+++ b/fixco_custom/models/account_move_reversal.py
@@ -46,8 +46,8 @@ class AccountMoveReversal(models.TransientModel):
moves_vals_list.append(move.copy_data({'date': self.date if self.date_mode == 'custom' else move.date})[0])
new_moves = self.env['account.move'].create(moves_vals_list)
-
- new_moves.action_post()
+ if new_moves.state != 'posted':
+ new_moves.action_post()
moves_to_redirect |= new_moves
move_line = self.env['account.move.line'].search([('move_id', '=', new_moves.id), ('account_id', '=', 347), ('journal_id', '=', 17)], limit=1)
if move_line and move_line.move_id.reversed_entry_id:
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py
index b8aa963..b880113 100755
--- a/fixco_custom/models/sale.py
+++ b/fixco_custom/models/sale.py
@@ -21,6 +21,31 @@ class SaleOrder(models.Model):
deadline_date = fields.Datetime('Deadline', copy=False)
+ total_discount = fields.Monetary(
+ string='Total Discount',
+ compute='_compute_total_discount',
+ currency_field='currency_id',
+ )
+
+ @api.depends(
+ 'order_line.price_unit',
+ 'order_line.product_uom_qty',
+ 'order_line.discount',
+ )
+ def _compute_total_discount(self):
+ for order in self:
+ total = 0.0
+ for line in order.order_line:
+ if line.discount:
+ line_discount = (
+ line.price_unit
+ * line.product_uom_qty
+ * line.discount / 100
+ )
+ total += line_discount
+ order.total_discount = total
+
+
def create_invoices(self):
created_invoices = self.env['account.move']
for order in self:
diff --git a/fixco_custom/views/account_move.xml b/fixco_custom/views/account_move.xml
index 4869981..4ff06f0 100644
--- a/fixco_custom/views/account_move.xml
+++ b/fixco_custom/views/account_move.xml
@@ -73,6 +73,9 @@
<field name="partner_id" position="after">
<field name="address" readonly="1" attrs="{'invisible': [('move_type', '!=', 'out_invoice')]}"/>
</field>
+ <field name="amount_untaxed" position="after">
+ <field name="total_discount"/>
+ </field>
<field name="reversed_entry_id" position="before">
<field name="reklas_id" readonly="1" attrs="{'invisible': [('move_type', '!=', 'entry')]}"/>
diff --git a/fixco_custom/views/sale_order.xml b/fixco_custom/views/sale_order.xml
index b29bcb9..2690710 100755
--- a/fixco_custom/views/sale_order.xml
+++ b/fixco_custom/views/sale_order.xml
@@ -33,6 +33,9 @@
<field name="partner_id" position="after">
<field name="address"/>
</field>
+ <field name="amount_tax" position="after">
+ <field name="total_discount"/>
+ </field>
<field name="client_order_ref" position="after">
<field name="order_reference" attrs="{'required': [('source', '!=', 'manual')]}"/>
<field name="invoice_mp" attrs="{'required': [('source', '!=', 'manual')]}"/>