summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/models/purchase_order.py102
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py32
-rwxr-xr-xindoteknik_custom/models/sale_order.py135
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml39
-rwxr-xr-xindoteknik_custom/views/sale_order.xml12
5 files changed, 268 insertions, 52 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index cb048182..2c9b72b1 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -1,11 +1,25 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, _
+from odoo.exceptions import AccessError, UserError, ValidationError
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
- procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status',readonly=True)
+ procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status', readonly=True)
+ total_margin = fields.Float(
+ 'Total Margin', compute='compute_total_margin',
+ help="Total Margin in Sales Order Header")
+ total_percent_margin = fields.Float(
+ 'Total Percent Margin', compute='compute_total_margin',
+ help="Total % Margin in Sales Order Header")
+ approval_status = fields.Selection([
+ ('pengajuan1', 'Approval Manager'), #siapa? darren - 11
+ ('pengajuan2', 'Approval Pimpinan'), #akbar - 7
+ ('approved', 'Approved'),
+ ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
+ count_line_product = fields.Float('Count Line Product', compute='compute_count_line_product')
+ delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
def get_procurement_status(self):
for purchase_order in self:
@@ -44,3 +58,87 @@ class PurchaseOrder(models.Model):
}
self.env['purchase.order.line'].sudo().create(values)
+ def compute_count_line_product(self):
+ for order in self:
+ count = 0
+ for line in order.order_line:
+ if line.product_id.type == 'product':
+ count += 1
+ if count == 0:
+ order.count_line_product = 1
+ 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_total_margin(self):
+ for po in self:
+ po.total_margin = 0
+ po.total_percent_margin = 0
+ for po in self:
+ total_margin = total_percent_margin = 0
+ for line in po.order_line:
+ if not line.product_id:
+ po.total_margin = 0
+ po.total_percent_margin = 0
+ continue
+ total_margin += line.item_margin
+ po.total_margin = total_margin
+ if po.amount_untaxed > 0:
+ total_percent_margin = round((total_margin / po.amount_untaxed), 2) * 100
+ po.total_percent_margin = total_percent_margin
+
+ 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'
+ 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")
+
+ def button_cancel(self):
+ res = super(PurchaseOrder, self).button_cancel()
+ self.approval_status = False
+ return res
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index b4be9ffc..55381c6d 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -4,6 +4,15 @@ 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')
@@ -25,3 +34,26 @@ 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
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 1db8a445..08e7281e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -19,6 +19,12 @@ class SaleOrder(models.Model):
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method')
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')
+ shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh '
+ 'Indoteknik, jika dicentang akan '
+ 'mempengaruhi margin')
+
def _compute_have_visit_service(self):
limit = 20000000
@@ -26,39 +32,56 @@ class SaleOrder(models.Model):
if self.amount_total > limit:
self.have_visit_service = True
- # def sale_order_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
- # # order.approval_status = "pengajuan2"
- # # break
- # elif line.item_percent_margin <= 40 and (self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
- # approval1 += 1
- # # order.approval_status = 'pengajuan1'
- # # break
- # if approval2 > 0:
- # order.approval_status = 'pengajuan2'
- # elif approval1 > 0:
- # order.approval_status = 'pengajuan1'
- # else:
- # raise UserError("Bisa langsung Confirm")
+ def sale_order_approve(self):
+ raise UserError("Bisa langsung Confirm")
+ # 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
+ # # order.approval_status = "pengajuan2"
+ # # break
+ # elif line.item_percent_margin <= 40 and (self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
+ # approval1 += 1
+ # # order.approval_status = 'pengajuan1'
+ # # break
+ # if approval2 > 0:
+ # order.approval_status = 'pengajuan2'
+ # elif approval1 > 0:
+ # order.approval_status = 'pengajuan1'
+ # else:
+ # raise UserError("Bisa langsung Confirm")
- # def action_cancel(self):
- # self.approval_status = False
- # return super(SaleOrder, self).action_cancel()
+ def action_cancel(self):
+ # self.approval_status = False
+ return super(SaleOrder, self).action_cancel()
def action_confirm(self):
- for line in self.order_line:
- if line.product_id.id == 232383:
- raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
res = super(SaleOrder, self).action_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):
+ # approval2 += 1
+ # elif line.item_percent_margin <= 40 and (
+ # self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
+ # approval1 += 1
+ # if approval2 > 0:
+ # raise UserError("Need Tyas / Akbar Approval, atau Approval manual dan lampirkan di Log Internal")
+ # elif approval1 > 0:
+ # raise UserError("Need Adela Approval")
+ # order.approval_status = 'approved'
return res
def compute_total_margin(self):
@@ -75,35 +98,47 @@ class SaleOrder(models.Model):
total_percent_margin = round((total_margin / order.amount_untaxed), 4) * 100
order.total_percent_margin = total_percent_margin
- # def action_confirm(self):
- # res = super(SaleOrder, self).action_confirm()
- # 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):
- # approval2 += 1
- # elif line.item_percent_margin <= 40 and (
- # self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
- # approval1 += 1
- # if approval2 > 0:
- # raise UserError("Need Tyas / Akbar Approval, atau Approval manual dan lampirkan di Log Internal")
- # elif approval1 > 0:
- # raise UserError("Need Adela Approval")
- # order.approval_status = 'approved'
- # return res
+ def compute_count_line_product(self):
+ for order in self:
+ count = 0
+ for line in order.order_line:
+ if line.product_id.type == 'product':
+ count += 1
+ if count == 0:
+ order.count_line_product = 1
+ 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
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
item_margin = fields.Float(
- 'Total Margin', compute='compute_item_margin',
+ 'Margin', compute='compute_item_margin',
help="Total Margin in Sales Order Header")
item_percent_margin = fields.Float(
- 'Total Percent Margin', compute='compute_item_margin',
+ '%Margin', compute='compute_item_margin',
help="Total % Margin in Sales Order Header")
+ vendor = fields.Many2one(
+ 'res.partner', string='Vendor', readonly=True,
+ states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
+ required=True, change_default=True, index=True, tracking=1,
+ domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",)
+ vendor = fields.Many2one(
+ 'res.partner', string='Vendor', readonly=True,
+ states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
+ change_default=True, index=True, tracking=1,
+ domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", )
+ purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0)
+ purchase_tax_id = fields.Many2one('account.tax', string='Tax',
+ domain=['|', ('active', '=', False), ('active', '=', True)])
def compute_item_margin(self):
for line in self:
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index f209d18a..ccedd857 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -14,8 +14,47 @@
attrs="{'invisible': ['|', ('sale_order_id', '=', False), ('state', 'not in', ['draft'])]}"
/>
</div>
+ <button id="draft_confirm" position="after">
+ <button name="po_approve"
+ string="Ask Approval"
+ type="object"
+ />
+ </button>
<field name="date_order" position="before">
<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>
+ <data>
+ <record id="rfq_order_tree_view_inherit" model="ir.ui.view">
+ <field name="name">Purchase</field>
+ <field name="model">purchase.order</field>
+ <field name="inherit_id" ref="purchase.purchase_order_kpis_tree"/>
+ <field name="arch" type="xml">
+ <field name="create_date" position="after">
+ <field name="approval_status" />
+ </field>
+ </field>
+ </record>
+ </data>
+ <data>
+ <record id="purchase_order_tree_view_inherit" model="ir.ui.view">
+ <field name="name">Purchase</field>
+ <field name="model">purchase.order</field>
+ <field name="inherit_id" ref="purchase.purchase_order_view_tree"/>
+ <field name="arch" type="xml">
+ <field name="invoice_status" position="after">
+ <field name="procurement_status" />
</field>
</field>
</record>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 19182a6b..03a6b45c 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -6,10 +6,22 @@
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
+ <button id="action_confirm" position="after">
+ <button name="sale_order_approve"
+ string="Ask Approval"
+ type="object"
+ />
+ </button>
<field name="payment_term_id" position="after">
+ <field name="shipping_cost_covered"/>
+ </field>
+ <field name="partner_shipping_id" position="after">
<field name="approval_status" />
</field>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_total']" position="after">
+ <field name="vendor" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
+ <field name="purchase_price" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
+ <field name="purchase_tax_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
<field name="item_margin" groups="sales_team.group_sale_manager"/>
<field name="item_percent_margin" groups="sales_team.group_sale_manager"/>
</xpath>