summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-27 14:42:59 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-27 14:42:59 +0700
commit3a8710d164ced77e532b0b96988d84bb08515602 (patch)
tree976ebb25089d80d938ca5bc9132aacb669e041cf
parent90ee21e0c1b2179b53d1dbadd6232bf22a3eea5a (diff)
Update purchase_order.py, sale_order.py, and sale_order.xml
-rwxr-xr-xindoteknik_custom/models/purchase_order.py45
-rwxr-xr-xindoteknik_custom/models/sale_order.py32
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
3 files changed, 51 insertions, 28 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 406b17fc..cffeff69 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -75,6 +75,10 @@ class PurchaseOrder(models.Model):
res = super(PurchaseOrder, self).button_confirm()
for line in self.order_line:
+ if not line.product_id:
+ continue
+ if line.product_id.type == 'service' and self.env.user.id != 6:
+ raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager")
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')
@@ -89,8 +93,10 @@ class PurchaseOrder(models.Model):
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 Manager")
- elif est_purchase_price != real_purchase_price and self.env.user.id != 6:
+ elif est_purchase_price < real_purchase_price and self.env.user.id != 6:
raise UserError("Beda Price dengan Sales, harus Approval Manager")
+ # elif line.product_id.type == 'service' and self.env.user_id != 6:
+ # raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager")
self.approval_status = 'approved'
return res
@@ -98,22 +104,29 @@ class PurchaseOrder(models.Model):
def po_approve(self):
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:
+ if not line.product_id:
+ continue
+ elif line.product_id.type == 'service' and self.env.user.id != 6:
approval += 1
+ else:
+ 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
+ elif line.product_id.type == 'service' and self.env.user.id != 6:
+ approval += 1
if approval > 0:
self.approval_status = "pengajuan1"
else:
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 73047171..70e2d63e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -21,10 +21,15 @@ class SaleOrder(models.Model):
have_visit_service = fields.Boolean(string='Have Visit Service', help='To compute is customer get visit service',
compute='_compute_have_visit_service')
count_line_product = fields.Float('Count Line Product', compute='compute_count_line_product')
- delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
+ # delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
+ delivery_amt = fields.Float('Delivery Amt')
shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh '
- 'Indoteknik, jika dicentang akan '
+ 'Indoteknik (Finance), jika dicentang akan '
'mempengaruhi margin')
+ shipping_paid_by = fields.Selection([
+ ('indoteknik', 'Indoteknik'),
+ ('customer', 'Customer')
+ ], string='Shipping Paid by', help='Siapa yang talangin Biaya kirim?',copy=False)
def _compute_have_visit_service(self):
limit = 20000000
@@ -39,10 +44,12 @@ class SaleOrder(models.Model):
raise UserError("Status harus draft atau sent")
approval1 = approval2 = 0
for line in order.order_line:
- if line.product_id.id == 232383:
- raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
if not line.product_id or line.product_id.type == 'service':
continue
+ if line.product_id.id == 232383:
+ raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
+ if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id:
+ raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval'))
if (line.item_percent_margin <= 15) and (
self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas
approval2 += 1
@@ -109,13 +116,14 @@ class SaleOrder(models.Model):
else:
order.count_line_product = count
- def compute_delivery_amount(self):
- for order in self:
- amount = 0
- for line in order.order_line:
- if line.product_id.type == 'service':
- amount += line.price_total
- order.delivery_amount = amount
+ # def compute_delivery_amount(self):
+ # for order in self:
+ # amount = 0
+ # for line in order.order_line:
+ # if line.product_id.type == 'service':
+ # amount += line.price_total
+ # order.delivery_amount = amount
+ # order.delivery_amt = amount
class SaleOrderLine(models.Model):
@@ -147,7 +155,7 @@ class SaleOrderLine(models.Model):
sales_price = line.price_reduce_taxexcl * line.product_uom_qty
# minus with delivery if covered by indoteknik
if line.order_id.shipping_cost_covered:
- sales_price -= round((line.order_id.delivery_amount / line.order_id.count_line_product), 2)
+ sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2)
purchase_price = line.purchase_price
if line.purchase_tax_id.price_include:
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 0e2d2923..2260ddc1 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -14,6 +14,8 @@
</button>
<field name="payment_term_id" position="after">
<field name="shipping_cost_covered"/>
+ <field name="shipping_paid_by"/>
+ <field name="delivery_amt"/>
</field>
<field name="partner_shipping_id" position="after">
<field name="approval_status" />