summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order_line.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-05-27 10:19:09 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-05-27 10:19:09 +0700
commitf0f414383b3bd34e6fce12e68e171014c08d2a55 (patch)
treef9eef4c1331f6507fadc680bdd801656ff9f8ea7 /indoteknik_custom/models/sale_order_line.py
parent431229f2a6f1203fbdfe470229e55da8ebd3ea01 (diff)
parentd3f530b94569059106164172485aaa9665e80709 (diff)
Merge branch 'odoo-backup' into CR/repeat-order
Diffstat (limited to 'indoteknik_custom/models/sale_order_line.py')
-rw-r--r--indoteknik_custom/models/sale_order_line.py67
1 files changed, 50 insertions, 17 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index aed95aab..9247d1c1 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -6,6 +6,7 @@ from datetime import datetime, timedelta
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
item_margin = fields.Float('Margin', compute='compute_item_margin', help="Total Margin in Sales Order Header")
+ item_before_margin = fields.Float('Before Margin', compute='compute_item_before_margin', help="Total Margin in Sales Order Header")
item_percent_margin = fields.Float('%Margin', compute='compute_item_margin', help="Total % Margin in Sales Order Header")
initial_discount = fields.Float('Initial Discount')
vendor_id = fields.Many2one(
@@ -40,6 +41,19 @@ class SaleOrderLine(models.Model):
qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan')
desc_updatable = fields.Boolean(string='desc boolean', default=True, compute='_get_desc_updatable')
+ def _get_outgoing_incoming_moves(self):
+ outgoing_moves = self.env['stock.move']
+ incoming_moves = self.env['stock.move']
+
+ for move in self.move_ids.filtered(lambda r: r.state != 'cancel' and not r.scrapped and self.product_id == r.product_id):
+ if move.location_dest_id.usage == "customer":
+ if not move.origin_returned_move_id or (move.origin_returned_move_id and move.to_refund):
+ outgoing_moves |= move
+ elif move.location_id.usage == "customer" and move.to_refund:
+ incoming_moves |= move
+
+ return outgoing_moves, incoming_moves
+
def _get_desc_updatable(self):
for line in self:
if line.product_id.id != 417724 and line.product_id.id:
@@ -146,6 +160,24 @@ class SaleOrderLine(models.Model):
if not line.margin_md:
line.margin_md = line.item_percent_margin
+ def compute_item_before_margin(self):
+ for line in self:
+ if not line.product_id or line.product_id.type == 'service' \
+ or line.price_unit <= 0 or line.product_uom_qty <= 0 \
+ or not line.vendor_id:
+ line.item_before_margin = 0
+ continue
+ # calculate margin without tax
+ sales_price = line.price_reduce_taxexcl * line.product_uom_qty
+
+ purchase_price = line.purchase_price
+ if line.purchase_tax_id.price_include:
+ purchase_price = line.purchase_price / 1.11
+
+ purchase_price = purchase_price * line.product_uom_qty
+ margin_per_item = sales_price - purchase_price
+ line.item_before_margin = margin_per_item
+
@api.onchange('vendor_id')
def onchange_vendor_id(self):
# TODO : need to change this logic @stephan
@@ -223,32 +255,33 @@ class SaleOrderLine(models.Model):
def _get_valid_purchase_price(self, purchase_price):
current_time = datetime.now()
delta_time = current_time - timedelta(days=365)
+ default_timestamp = datetime(1970, 1, 1, 0, 0, 0)
# delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
price = 0
- taxes = ''
+ taxes = 24
vendor_id = ''
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
-
- if purchase_price.taxes_product_id.type_tax_use == 'purchase':
- price = purchase_price.product_price
- taxes = purchase_price.taxes_product_id.id
+
+ # if purchase_price.taxes_product_id.type_tax_use == 'purchase':
+ price = purchase_price.product_price
+ taxes = purchase_price.taxes_product_id.id or 24
+ vendor_id = purchase_price.vendor_id.id
+ if delta_time > human_last_update:
+ price = 0
+ taxes = 24
+ vendor_id = ''
+
+ if system_last_update > human_last_update:
+ #if purchase_price.taxes_system_id.type_tax_use == 'purchase':
+ price = purchase_price.system_price
+ taxes = purchase_price.taxes_system_id.id or 24
vendor_id = purchase_price.vendor_id.id
- if delta_time > human_last_update:
+ if delta_time > system_last_update:
price = 0
- taxes = ''
+ taxes = 24
vendor_id = ''
-
- if system_last_update > human_last_update:
- if purchase_price.taxes_system_id.type_tax_use == 'purchase':
- price = purchase_price.system_price
- taxes = purchase_price.taxes_system_id.id
- vendor_id = purchase_price.vendor_id.id
- if delta_time > system_last_update:
- price = 0
- taxes = ''
- vendor_id = ''
return price, taxes, vendor_id