Skip to content

Commit

Permalink
Merge PR #12 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Aug 2, 2024
2 parents 18a5e48 + 5a884f6 commit 2586445
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 2 deletions.
1 change: 1 addition & 0 deletions ssi_purchase/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from . import (
purchase_order_type,
purchase_order,
purchase_order_line,
)
30 changes: 29 additions & 1 deletion ssi_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ def _compute_policy(self):
compute="_compute_total_qty",
store=True,
)

qty_invoiced = fields.Float(
string="Qty Invoiced",
compute="_compute_qty_invoice",
store=True,
)
percent_invoiced = fields.Float(
string="Percent Invoiced",
compute="_compute_qty_invoice",
store=True,
)
approve_ok = fields.Boolean(
string="Can Approve",
compute="_compute_policy",
Expand Down Expand Up @@ -138,6 +147,25 @@ def _compute_policy(self):
compute_sudo=True,
)

@api.depends(
"order_line",
"order_line.product_uom_qty",
"order_line.qty_invoiced",
"total_qty",
)
def _compute_qty_invoice(self):
for record in self:
qty_invoiced = percent_invoiced = 0.0
for line in record.order_line:
qty_invoiced += line.qty_invoiced
if record.total_qty != 0.0:
try:
percent_invoiced = qty_invoiced / record.total_qty
except ZeroDivisionError:
percent_invoiced = 0.0
record.qty_invoiced = qty_invoiced
record.percent_invoiced = percent_invoiced

@api.model
def default_get(self, fields):
_super = super(PurchaseOrder, self)
Expand Down
33 changes: 33 additions & 0 deletions ssi_purchase/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseOrderLine(models.Model):
_name = "purchase.order.line"
_inherit = [
"purchase.order.line",
]

percent_invoiced = fields.Float(
string="Percent Invoiced",
compute="_compute_percent_invoiced",
store=True,
compute_sudo=True,
)

@api.depends(
"qty_invoiced",
"product_uom_qty",
)
def _compute_percent_invoiced(self):
for record in self:
result = 0.0
if record.product_uom_qty != 0.0:
try:
result = record.qty_invoiced / record.product_uom_qty
except ZeroDivisionError:
result = 0.0
record.percent_invoiced = result
18 changes: 18 additions & 0 deletions ssi_purchase/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<field name="id" optional="hide" />
<field name="display_name" string="# Document" />
</xpath>
<xpath expr="//field[@name='state']" position="before">
<field name="percent_invoiced" widget="percentage" />
</xpath>
<xpath expr="//field[@name='state']" position="attributes">
<attribute name="invisible">0</attribute>
</xpath>
<xpath expr="//field[@name='invoice_status']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

Expand Down Expand Up @@ -201,8 +210,17 @@
<xpath expr="//page[@name='products']/group[1]" position="before">
<group name="group_extra" colspan="4" col="2">
<field name="total_qty" />
<field name="qty_invoiced" />
<field name="percent_invoiced" widget="percentage" />
</group>
</xpath>

<xpath
expr="//field[@name='order_line']/tree/field[@name='price_tax']"
position="after"
>
<field name="percent_invoiced" widget="percentage" />
</xpath>
</field>
</record>

Expand Down
3 changes: 2 additions & 1 deletion ssi_purchase_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"installable": True,
"application": True,
"depends": [
"purchase",
"ssi_purchase",
"stock",
],
"data": [
"security/res_group_data.xml",
"security/ir_rule_data.xml",
"views/stock_warehouse_views.xml",
"views/purchase_order_views.xml",
],
"demo": [],
}
2 changes: 2 additions & 0 deletions ssi_purchase_stock/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
from . import (
stock_warehouse,
res_users,
purchase_order,
purchase_order_line,
)
48 changes: 48 additions & 0 deletions ssi_purchase_stock/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseOrder(models.Model):
_name = "purchase.order"
_inherit = [
"purchase.order",
]

qty_to_receive = fields.Float(
string="Qty To Receive",
compute="_compute_receive",
store=True,
)
qty_received = fields.Float(
string="Qty Received",
compute="_compute_receive",
store=True,
)
percent_received = fields.Float(
string="Percent Received",
compute="_compute_receive",
store=True,
)

@api.depends(
"order_line",
"order_line.qty_to_receive",
"order_line.qty_received",
)
def _compute_receive(self):
for record in self:
qty_to_receive = qty_received = percent_received = 0.0
for line in record.order_line:
qty_to_receive += line.qty_to_receive
qty_received += line.qty_received
if qty_to_receive != 0.0:
try:
percent_received = qty_received / qty_to_receive
except ZeroDivisionError:
percent_received = 0.0
record.qty_received = qty_received
record.percent_received = percent_received
record.qty_to_receive = qty_to_receive
44 changes: 44 additions & 0 deletions ssi_purchase_stock/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseOrderLine(models.Model):
_name = "purchase.order.line"
_inherit = [
"purchase.order.line",
]

percent_received = fields.Float(
string="Percent Received",
compute="_compute_receive",
store=True,
compute_sudo=True,
)
qty_to_receive = fields.Float(
string="Qty To Receive",
compute="_compute_receive",
store=True,
compute_sudo=True,
)

@api.depends(
"qty_received",
"product_uom_qty",
)
def _compute_receive(self):
for record in self:
percent_received = qty_to_receive = qty_recieved = 0.0
if record.product_id.type != "service":
qty_to_receive = record.product_uom_qty
qty_recieved = record.qty_received

if qty_to_receive != 0.0:
try:
percent_received = qty_recieved / qty_to_receive
except ZeroDivisionError:
percent_received = 0.0
record.percent_received = percent_received
record.qty_to_receive = qty_to_receive
50 changes: 50 additions & 0 deletions ssi_purchase_stock/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 OpenSynergy Indonesia
Copyright 2022 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="purchase_order_view_tree" model="ir.ui.view">
<field name="name">purchase.order.view.tree</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="ssi_purchase.purchase_order_view_tree" />
<field name="priority" eval="100" />
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='percent_invoiced']" position="before">
<field name="percent_received" widget="percentage" />
</xpath>
</data>
</field>
</record>

<record id="purchase_order_view_form1" model="ir.ui.view">
<field name="name">purchase.order - form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<data>
<xpath
expr="//field[@name='order_line']/tree/field[@name='price_tax']"
position="after"
>
<field name="percent_received" widget="percentage" />
</xpath>
</data>
</field>
</record>

<record id="purchase_order_view_form2" model="ir.ui.view">
<field name="name">purchase.order - form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="ssi_purchase.purchase_order_form_view_form" />
<field name="arch" type="xml">
<data>
<xpath expr="//group[@name='group_extra']" position="inside">
<field name="qty_received" />
<field name="qty_to_receive" />
<field name="percent_received" widget="percentage" />
</xpath>
</data>
</field>
</record>
</odoo>

0 comments on commit 2586445

Please sign in to comment.