summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-26 18:25:41 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-26 18:25:41 +0700
commit7ae5b8b7baafb9ed302c3c3e54f3f44664651c06 (patch)
tree930ec4518e3e36f9e0a6bc980a931c1f4ed37120
parent98d8bb612184f5354c076f52143afcfad4e05e6f (diff)
Update purchase_order.py, purchase_order_line.py, and 2 more files...
-rwxr-xr-xindoteknik_custom/models/purchase_order.py80
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py68
-rwxr-xr-xindoteknik_custom/models/sale_order.py2
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml8
4 files changed, 78 insertions, 80 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 2c9b72b1..889fc80e 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -96,47 +96,51 @@ class PurchaseOrder(models.Model):
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
- # for line in self.order_line:
- # if line.product_id.id == 232383:
- # raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
- for order in self:
- approval1 = approval2 = 0
- for line in order.order_line:
- if not line.product_id:
- continue
- if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \
- (self.env.user.id != 6 and self.env.user.id != 7): # tyas or akbar
- approval2 += 1
- elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \
- (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): # tyas or akbar or darren
- approval1 += 1
- if approval2 > 0:
- raise UserError("Need Tyas / Akbar Approval")
- elif approval1 > 0:
- raise UserError("Need Adela Approval")
- order.approval_status = 'approved'
+
+ for line in self.order_line:
+ sale_order_line = self.env['sale.order.line'].search(
+ [('product_id', '=', line.product_id.id),
+ ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl')
+
+ est_purchase_price = sale_order_line.purchase_price
+ real_purchase_price = line.price_unit
+ real_tax = real_tax_amount = count_real_tax = 0
+ for tax in line.taxes_id:
+ count_real_tax += 1
+ real_tax = tax
+ real_tax_amount += tax.amount
+ if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \
+ or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and (self.env.user.id != 6):
+ raise UserError("Beda tax amount dengan Sales, harus Approval Pak Tyas")
+ elif est_purchase_price != real_purchase_price and self.env.user.id != 6:
+ raise UserError("Beda Price dengan Sales, harus Approval Pak Tyas")
+ self.approval_status = 'approved'
+
return res
def po_approve(self):
- for order in self:
- if order.state == 'cancel' or order.state == 'done' or order.state == 'sale':
- raise UserError("Status harus draft atau sent")
- approval1 = approval2 = 0
- for line in order.order_line:
- if not line.product_id:
- continue
- if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \
- (self.env.user.id != 6 and self.env.user.id != 7):
- approval2 += 1
- elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \
- (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11):
- approval1 += 1
- if approval2 > 0:
- order.approval_status = 'pengajuan2'
- elif approval1 > 0:
- order.approval_status = 'pengajuan1'
- else:
- raise UserError("Bisa langsung Confirm")
+ approval = 0
+ for line in self.order_line:
+ sale_order_line = self.env['sale.order.line'].search(
+ [('product_id', '=', line.product_id.id),
+ ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl')
+
+ est_purchase_price = sale_order_line.purchase_price
+ real_purchase_price = line.price_unit
+ real_tax = real_tax_amount = count_real_tax = 0
+ for tax in line.taxes_id:
+ count_real_tax += 1
+ real_tax = tax
+ real_tax_amount += tax.amount
+ if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \
+ or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and self.env.user.id != 6:
+ approval += 1
+ elif est_purchase_price != real_purchase_price and self.env.user.id != 6:
+ approval += 1
+ if approval > 0:
+ self.approval_status = "pengajuan1"
+ else:
+ raise UserError("Bisa langsung Confirm")
def button_cancel(self):
res = super(PurchaseOrder, self).button_cancel()
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index 55381c6d..4229fcea 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -1,18 +1,10 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, _
+from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
- sales_price = fields.Float(
- 'Sales Price', compute='compute_item_margin',
- help="Sales Price in Purchase Order Line")
- item_margin = fields.Float(
- 'Total Margin', compute='compute_item_margin',
- help="Total Margin in Purchase Order Line")
- item_percent_margin = fields.Float(
- 'Total Percent Margin', compute='compute_item_margin',
- help="Total % Margin in Purchase Order Line")
# Override method from addons/purchase/models/purchase.py
@api.onchange('product_qty', 'product_uom')
@@ -35,25 +27,37 @@ class PurchaseOrderLine(models.Model):
self.price_unit = price_unit
return res
- def compute_item_margin(self):
- for line in self:
- if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id:
- line.item_margin = 0
- line.item_percent_margin = 0
- continue
- sale_order_line = self.env['sale.order.line'].search(
- [('product_id', '=', line.product_id.id),
- ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl')
-
- # untaxed sales price
- sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty
- # must add expedition price in sales_price, expedition payed by customer?
- # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2)
- # untaxed purchase price
- purchase_price = line.price_subtotal
- # must add expedition price in purchase_price as expenses
- purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2)
- margin_per_item = sales_price - purchase_price
- line.item_margin = margin_per_item
- if sales_price > 0:
- line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file
+ # def compute_item_margin(self):
+ # for line in self:
+ # if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id:
+ # line.item_margin = 0
+ # line.item_percent_margin = 0
+ # continue
+ # sale_order_line = self.env['sale.order.line'].search(
+ # [('product_id', '=', line.product_id.id),
+ # ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl')
+ #
+ # est_purchase_price = sale_order_line.purchase_price
+ # real_purchase_price = line.price_unit
+ # real_tax = 0
+ # real_tax_amount = 0
+ # count_real_tax = 0
+ # for tax in line.taxes_id:
+ # count_real_tax += 1
+ # real_tax = tax
+ # real_tax_amount += tax.amount
+ # if sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1:
+ # raise UserError("Beda tax amount dengan Sales")
+ #
+ # # untaxed sales price
+ # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty
+ # # must add expedition price in sales_price, expedition payed by customer?
+ # # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2)
+ # # untaxed purchase price
+ # purchase_price = line.price_subtotal
+ # # must add expedition price in purchase_price as expenses
+ # purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2)
+ # margin_per_item = sales_price - purchase_price
+ # line.item_margin = margin_per_item
+ # if sales_price > 0:
+ # line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index e317fb8e..1fb88495 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -161,8 +161,6 @@ class SaleOrderLine(models.Model):
def onchange_vendor_id(self):
if not self.product_id or self.product_id.type == 'service':
return
- test1 = self.vendor_id.id
- test2 = self.product_id.id
purchase_price = self.env['purchase.pricelist'].search(
[('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1)
self.purchase_price = purchase_price.product_price
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index ccedd857..37b9c0cb 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -24,14 +24,6 @@
<field name="sale_order_id" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/>
<field name="approval_status"/>
</field>
- <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
- <field name="item_margin"/>
- <field name="item_percent_margin"/>
- </xpath>
- <field name="amount_total" position="after">
- <field name="total_margin"/>
- <field name="total_percent_margin"/>
- </field>
</field>
</record>
</data>