Skip to content

Commit

Permalink
[IMP] repair_order_cost: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jun 26, 2024
1 parent 435ab3c commit d5998c3
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 58 deletions.
6 changes: 3 additions & 3 deletions repair_order_cost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _post_install_put_cost_in_repair_orders(cr, registry):
for repair in repairs:
for operation in repair.operations:
operation.material_cost = (
operation.product_uom_qty * operation.product_id.standard_price)
operation.product_uom_qty * operation.product_id.standard_price
)
for line in repair.fees_lines:
line.operations_cost = (
line.product_uom_qty * line.product_id.standard_price)
line.operations_cost = line.product_uom_qty * line.product_id.standard_price
7 changes: 2 additions & 5 deletions repair_order_cost/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"category": "Inventory/Inventory",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "https://www.avanzosc.es",
"depends": [
"product",
"repair"
],
"website": "https://github.com/avanzosc/mrp-repair-addons",
"depends": ["product", "repair"],
"data": [
"security/repair_order_cost_groups.xml",
"views/repair_order_views.xml",
Expand Down
7 changes: 2 additions & 5 deletions repair_order_cost/models/repair_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
class RepairFee(models.Model):
_inherit = "repair.fee"

operations_cost = fields.Float(
string="Operations cost", digits="Product Price"
)
operations_cost = fields.Float(string="Operations cost", digits="Product Price")

@api.onchange("repair_id", "product_id", "product_uom_qty")
def onchange_product_id(self):
result = super(RepairFee, self).onchange_product_id()
operations_cost = 0
if self.product_id:
operations_cost = (
self.product_uom_qty * self.product_id.standard_price)
operations_cost = self.product_uom_qty * self.product_id.standard_price
self.operations_cost = operations_cost
return result
7 changes: 2 additions & 5 deletions repair_order_cost/models/repair_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
class RepairLine(models.Model):
_inherit = "repair.line"

material_cost = fields.Float(
string="Material cost", digits="Product Price"
)
material_cost = fields.Float(string="Material cost", digits="Product Price")

@api.onchange("repair_id", "product_id", "product_uom_qty")
def onchange_product_id(self):
result = super(RepairLine, self).onchange_product_id()
material_cost = 0
if self.type and self.type == "add" and self.product_id:
material_cost = (
self.product_uom_qty * self.product_id.standard_price)
material_cost = self.product_uom_qty * self.product_id.standard_price
self.material_cost = material_cost
return result
35 changes: 23 additions & 12 deletions repair_order_cost/models/repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,41 @@ class RepairOrder(models.Model):
_inherit = "repair.order"

material_cost = fields.Float(
string="Material cost", digits="Product Price",
compute="_compute_repair_costs", store=True, copy=False
string="Material cost",
digits="Product Price",
compute="_compute_repair_costs",
store=True,
copy=False,
)
operations_cost = fields.Float(
string="Operations cost", digits="Product Price",
compute="_compute_repair_costs", store=True, copy=False
string="Operations cost",
digits="Product Price",
compute="_compute_repair_costs",
store=True,
copy=False,
)
total_repair_cost = fields.Float(
string="Total repair cost", digits="Product Price",
compute="_compute_repair_costs", store=True, copy=False
string="Total repair cost",
digits="Product Price",
compute="_compute_repair_costs",
store=True,
copy=False,
)

@api.depends("operations", "operations.material_cost",
"fees_lines", "fees_lines.operations_cost")
@api.depends(
"operations",
"operations.material_cost",
"fees_lines",
"fees_lines.operations_cost",
)
def _compute_repair_costs(self):
for repair in self:
material_cost = 0
operations_cost = 0
if repair.operations:
material_cost = sum(
repair.operations.mapped("material_cost"))
material_cost = sum(repair.operations.mapped("material_cost"))
if repair.fees_lines:
operations_cost = sum(
repair.fees_lines.mapped("operations_cost"))
operations_cost = sum(repair.fees_lines.mapped("operations_cost"))
repair.material_cost = material_cost
repair.operations_cost = operations_cost
repair.total_repair_cost = material_cost + operations_cost
5 changes: 4 additions & 1 deletion repair_order_cost/security/repair_order_cost_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<odoo>
<record id="group_show_repair_order_cost" model="res.groups">
<field name="name">Show repair order costs</field>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>
</odoo>
89 changes: 62 additions & 27 deletions repair_order_cost/views/repair_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,60 @@
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='operations']/form//field[@name='currency_id']" position="after">
<field name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"/>
<xpath
expr="//field[@name='operations']/form//field[@name='currency_id']"
position="after"
>
<field
name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"
/>
</xpath>
<xpath expr="//field[@name='operations']/tree//field[@name='tax_id']" position="after">
<field name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show" sum="Total material cost"/>
<xpath
expr="//field[@name='operations']/tree//field[@name='tax_id']"
position="after"
>
<field
name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show"
sum="Total material cost"
/>
</xpath>
<xpath expr="//field[@name='fees_lines']/form//field[@name='currency_id']" position="after">
<field name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"/>
<xpath
expr="//field[@name='fees_lines']/form//field[@name='currency_id']"
position="after"
>
<field
name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"
/>
</xpath>
<xpath expr="//field[@name='fees_lines']/tree//field[@name='tax_id']" position="after">
<field name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show" sum="Total operations cost"/>
<xpath
expr="//field[@name='fees_lines']/tree//field[@name='tax_id']"
position="after"
>
<field
name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show"
sum="Total operations cost"
/>
</xpath>
<notebook position="before">
<group colspan="4" col="6" groups="repair_order_cost.group_show_repair_order_cost">
<group
colspan="4"
col="6"
groups="repair_order_cost.group_show_repair_order_cost"
>
<group>
<field name="material_cost"/>
<field name="material_cost" />
</group>
<group>
<field name="operations_cost"/>
<field name="operations_cost" />
</group>
<group>
<field name="total_repair_cost"/>
<field name="total_repair_cost" />
</group>
</group>
</notebook>
Expand All @@ -43,15 +69,24 @@
<field name="inherit_id" ref="repair.view_repair_order_tree" />
<field name="arch" type="xml">
<field name="guarantee_limit" position="after">
<field name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show" sum="Total material cost"/>
<field name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show" sum="Total operations cost"/>
<field name="total_repair_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show" sum="Total cost"/>
<field
name="material_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show"
sum="Total material cost"
/>
<field
name="operations_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show"
sum="Total operations cost"
/>
<field
name="total_repair_cost"
groups="repair_order_cost.group_show_repair_order_cost"
optional="show"
sum="Total cost"
/>
</field>
</field>
</record>
Expand Down

0 comments on commit d5998c3

Please sign in to comment.