Skip to content

Commit

Permalink
[MIG] mrp_repair historical: Migration of mrp_repair_partner_lot to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Jan 10, 2025
1 parent edb6bf0 commit 96a0f66
Show file tree
Hide file tree
Showing 24 changed files with 455 additions and 394 deletions.
2 changes: 1 addition & 1 deletion mrp_repair_date/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Repair Date
===========

* This module in "mrp.repair" object creates new fields of dates: Scheduled
* This module in "repair.order" object creates new fields of dates: Scheduled
departure date, start date, end date. Also it is shown in the tree view, the
date of creation of the object.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import models
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

Expand All @@ -7,7 +6,7 @@
"version": "8.0.1.2.0",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "http://www.avanzosc.es",
"website": "https://github.com/avanzosc/mrp-repair-addons",
"contributors": [
"Ana Juaristi <[email protected]>",
"Alfredo de la Fuente <[email protected]>",
Expand All @@ -17,7 +16,7 @@
"stock",
"mrp_repair",
"product_supplierinfo_for_customer",
"mrp_calendar_view"
"repair_calendar_view",
],
"data": [
"security/ir.model.access.csv",
Expand Down
18 changes: 18 additions & 0 deletions mrp_repair_historical/data/report_paperformat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odooo>
<record id="paperformat_mrp_repair_partner_lot" model="report.paperformat">
<field name="name">MRP repair partner lot</field>
<field name="default" eval="True" />
<field name="format">A4</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Landscape</field>
<field name="margin_top">30</field>
<field name="margin_bottom">10</field>
<field name="margin_left">7</field>
<field name="margin_right">7</field>
<field name="header_line" eval="False" />
<field name="header_spacing">35</field>
<field name="dpi">90</field>
</record>
</odooo>
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ msgstr "NIF:"

#. module: mrp_repair_partner_lot
#: view:mrp.repair.customer.lot:mrp_repair_partner_lot.mrp_repair_customer_lot_view_search
#: field:mrp.repair.customer.lot,repair_date:0
#: field:mrp.repair.customer.lot,date_repair:0
msgid "Repair date"
msgstr "Fecha reparación"

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import mrp_repair
from . import repair_order_customer_lot
from . import product_supplierinfo
55 changes: 55 additions & 0 deletions mrp_repair_historical/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, models
from odoo.osv import expression


class ProductSupplierinfo(models.Model):
_inherit = "product.supplierinfo"

def name_get(self):
result = []
for suppinfo in self:
base_result = super(ProductSupplierinfo, suppinfo).name_get()
for suppinfo_id, name in base_result:
if self.env.context.get("show_customer_product_code"):
names = []
code = (
suppinfo.product_code
or suppinfo.product_tmpl_id.default_code
or False
)
if code:
names.append(f"[{code}]")
names.append(suppinfo.product_name or suppinfo.product_tmpl_id.name)
if names:
name = " ".join(names)
result.append((suppinfo_id, name))
return result

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
):
if args is None:
args = []
results = super()._name_search(
name, args, operator, limit, name_get_uid=name_get_uid
)
products = self.env["product.product"].search([("name", operator, name)])
domain = [
"|",
("product_code", operator, name),
("product_name", operator, name),
]
if products:
args = expression.OR(
[
domain,
[("product_tmpl_id", "in", products.mapped("product_tmpl_id").ids)],
]
)
else:
args += domain
more_results = self.search(args, limit=limit)
return more_results.name_get() or results
37 changes: 37 additions & 0 deletions mrp_repair_historical/models/repair_order_customer_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from odoo import api, fields, models


class MrpRepairCustomerLot(models.Model):
_name = "repair.order.customer.lot"
_description = "MRP Repair Customer Lot"

repair_id = fields.Many2one(comodel_name="repair.order", required=True)
date_repair = fields.Datetime(related="repair_id.date_repair", store=True)
customer_id = fields.Many2one(
comodel_name="res.partner",
related="repair_id.partner_id",
store=True,
)
customer_product_code = fields.Char()
lot_id = fields.Many2one(comodel_name="stock.production.lot", required=True)
product_variant_id = fields.Many2one(comodel_name="product.product", required=True)
product_template_id = fields.Many2one(
comodel_name="product.template",
related="product_variant_id.product_tmpl_id",
store=True,
)
internal_reference = fields.Char(
related="product_variant_id.default_code",
store=True,
)
quantity = fields.Integer()
breakdown_description = fields.Text()
cause = fields.Text()
repair_made = fields.Text()
repairable = fields.Boolean()

@api.onchange("lot_id")
def _onchange_lot_id(self):
"""Set the product variant when a lot is selected."""
for record in self:
record.product_variant_id = record.lot_id.product_id
111 changes: 111 additions & 0 deletions mrp_repair_historical/report/mrp_repair_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="report_mrp_repair_partner_lot_printing">
<t t-call="web.external_layout">
<t
t-set="o"
t-value="o.with_context({'show_customer_product_code':True})"
/>
<div class="page">
<div class="oe_structure" />
<div class="row">
<div class="col-6">
<div
t-field="o.company_id.partner_id"
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "email"], "no_marker": true}'
/>
<p t-if="o.company_id.partner_id.vat">VAT: <span
t-field="o.company_id.partner_id.vat"
/></p>
</div>
<div class="col-6">
<strong
t-if="o.address_id == o.partner_invoice_id"
>Invoice and Shipping Address:</strong>
<div t-if="o.partner_invoice_id">
<strong
t-if="o.address_id != o.partner_invoice_id"
>Invoice Address: </strong>
<div
t-field="o.partner_invoice_id"
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "email"], "no_marker": true}'
/>
<p t-if="o.partner_id.vat">VAT: <span
t-field="o.partner_id.vat"
/></p>
</div>
<div t-if="o.address_id != o.partner_invoice_id" class="mt-3">
<strong>Shipping Address:</strong>
<div
t-field="o.address_id"
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "email"], "no_marker": true}'
/>
<p t-if="o.partner_id.vat">VAT: <span
t-field="o.partner_id.vat"
/></p>
</div>
</div>
</div>

<h2>
<span>Repair Report No.:</span>
<span t-field="o.name" />
</h2>

<div class="row mt-4 mb-4">
<div class="col-3">
<strong>Repair Date:</strong>
<br />
<span t-field="o.date_repair" t-options='{"widget": "date"}' />
</div>
<div t-if="o.user_id.name" class="col-3">
<strong>Responsible:</strong>
<p t-field="o.user_id.name" />
</div>
</div>

<table class="table table-condensed">
<thead>
<tr>
<th>Customer Product Code</th>
<th>Product Variant</th>
<th>Product Template</th>
<th>Internal Reference</th>
<th>Lot/Serial Number</th>
<th>Quantity</th>
<th>Breakdown Description</th>
<th>Cause</th>
<th>Repair Made</th>
<th>Repairable</th>
</tr>
</thead>
<tbody>
<tr t-foreach="o.customer_lot_ids" t-as="line">
<td><span t-field="line.customer_product_code" /></td>
<td><span t-field="line.product_variant_id" /></td>
<td><span t-field="line.product_template_id" /></td>
<td><span t-field="line.internal_reference" /></td>
<td><span t-field="line.lot_id" /></td>
<td><span t-field="line.quantity" /></td>
<td><span t-field="line.breakdown_description" /></td>
<td><span t-field="line.cause" /></td>
<td><span t-field="line.repair_made" /></td>
<td><span t-field="line.repairable" /></td>
</tr>
</tbody>
</table>
<div class="oe_structure" />
</div>
</t>
</template>

<template id="report_mrp_repair_partner_lot">
<t t-call="web.external_layout">
<t t-foreach="docs" t-as="o">
<t
t-call="mrp_repair_partner_lot.report_mrp_repair_partner_lot_printing"
/>
</t>
</t>
</template>
</odoo>
3 changes: 3 additions & 0 deletions mrp_repair_historical/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_repair_order_customer_lot_manager,repair.order.customer.lot,model_repair_order_customer_lot,mrp.group_mrp_manager,1,1,1,1
access_repair_order_customer_lot_user,repair.order.customer.lot,model_repair_order_customer_lot,mrp.group_mrp_user,1,1,1,1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import test_mrp_repair_partner_lot
97 changes: 97 additions & 0 deletions mrp_repair_historical/tests/test_mrp_repair_partner_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2019 Alfredo de la Fuente - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import odoo.tests.common as common
from odoo import fields


class TestMrpRepairPartnerLot(common.TransactionCase):

def setUp(self):
super().setUp()
self.repair_model = self.env["repair.order"]
self.supplierinfo_model = self.env["product.supplierinfo"]
self.supplier = self.env.ref("base.partner_root")
self.product = self.env["product.template"].create(
{
"name": "Product",
"default_code": "CODE",
}
)
self.supplierinfo = self.supplierinfo_model.create(
{
"name": self.supplier.id,
"product_tmpl_id": self.product.id,
"product_code": "SUP CODE",
"product_name": "Product Name",
}
)

def test_mrp_repair_partner_lot(self):
suppinfo = self.supplierinfo_model.name_search("CODE")
self.assertEqual(self.supplierinfo.name_get(), suppinfo)
self.assertEqual(self.supplierinfo.display_name, self.supplierinfo.name.name)
self.assertEqual(
self.supplierinfo.with_context(
show_customer_product_code=True
).display_name,
"[{}] {}".format(
self.supplierinfo.product_code, self.supplierinfo.product_name
),
)
self.supplierinfo.write(
{
"product_code": "",
"product_name": "Product Name",
}
)
self.supplierinfo.invalidate_cache()
self.assertEqual(
self.supplierinfo.with_context(
show_customer_product_code=True
).display_name,
"[{}] {}".format(
self.supplierinfo.product_tmpl_id.default_code,
self.supplierinfo.product_name,
),
)
self.supplierinfo.write(
{
"product_code": "SUP CODE",
"product_name": "",
}
)
self.supplierinfo.invalidate_cache()
self.assertEqual(
self.supplierinfo.with_context(
show_customer_product_code=True
).display_name,
"[{}] {}".format(
self.supplierinfo.product_code, self.supplierinfo.product_tmpl_id.name
),
)
self.supplierinfo.write(
{
"product_code": "",
"product_name": "",
}
)
self.supplierinfo.invalidate_cache()
self.assertEqual(
self.supplierinfo.with_context(
show_customer_product_code=True
).display_name,
"[{}] {}".format(
self.supplierinfo.product_tmpl_id.default_code,
self.supplierinfo.product_tmpl_id.name,
),
)

def test_mrp_repair_partner_lot_date_repair(self):
self.repair = self.repair_model.search([], limit=1)
self.repair.write(
{"customer_lot_ids": [(0, 0, {"product_code": self.supplierinfo.id})]}
)
self.assertEqual(
fields.Datetime.from_string(self.repair.date_repair).date(),
fields.Date.from_string(self.repair.customer_lot_ids[0].date_repair),
)
Loading

0 comments on commit 96a0f66

Please sign in to comment.