Merge pull request #254 from ForgeFlow/13.0_fix_product_templates_multicompany

[13.0][FIX/IMP] Make RMA Operation settings company dependent
This commit is contained in:
Jordi Ballester Alomar
2022-05-19 19:57:18 +02:00
committed by GitHub
9 changed files with 69 additions and 15 deletions

View File

@@ -46,7 +46,7 @@ repos:
- --remove-duplicate-keys - --remove-duplicate-keys
- --remove-unused-variables - --remove-unused-variables
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 19.10b0 rev: 22.3.0
hooks: hooks:
- id: black - id: black
- repo: https://github.com/pre-commit/mirrors-prettier - repo: https://github.com/pre-commit/mirrors-prettier

View File

@@ -8,10 +8,14 @@ class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"
rma_customer_operation_id = fields.Many2one( rma_customer_operation_id = fields.Many2one(
comodel_name="rma.operation", string="Default RMA Customer Operation" company_dependent=True,
comodel_name="rma.operation",
string="Default RMA Customer Operation",
) )
rma_supplier_operation_id = fields.Many2one( rma_supplier_operation_id = fields.Many2one(
comodel_name="rma.operation", string="Default RMA Supplier Operation" company_dependent=True,
comodel_name="rma.operation",
string="Default RMA Supplier Operation",
) )
rma_approval_policy = fields.Selection( rma_approval_policy = fields.Selection(
related="categ_id.rma_approval_policy", readonly=True related="categ_id.rma_approval_policy", readonly=True

View File

@@ -19,8 +19,12 @@ class ProductCategory(models.Model):
"this policy will request the RMA manager approval.", "this policy will request the RMA manager approval.",
) )
rma_customer_operation_id = fields.Many2one( rma_customer_operation_id = fields.Many2one(
comodel_name="rma.operation", string="Default RMA Customer Operation" company_dependent=True,
comodel_name="rma.operation",
string="Default RMA Customer Operation",
) )
rma_supplier_operation_id = fields.Many2one( rma_supplier_operation_id = fields.Many2one(
comodel_name="rma.operation", string="Default RMA Supplier Operation" company_dependent=True,
comodel_name="rma.operation",
string="Default RMA Supplier Operation",
) )

View File

@@ -194,8 +194,7 @@ class RmaOrder(models.Model):
return self._view_shipments(result, shipments) return self._view_shipments(result, shipments)
def _get_valid_lines(self): def _get_valid_lines(self):
""":return: A recordset of rma lines. """:return: A recordset of rma lines."""
"""
self.ensure_one() self.ensure_one()
return self.rma_line_ids return self.rma_line_ids

View File

@@ -425,7 +425,9 @@ class TestRma(common.SavepointCase):
sum(lines.mapped("in_shipment_count")), 3, "Incorrect In Shipment Count" sum(lines.mapped("in_shipment_count")), 3, "Incorrect In Shipment Count"
) )
self.assertEqual( self.assertEqual(
sum(lines.mapped("out_shipment_count")), 3, "Incorrect Out Shipment Count", sum(lines.mapped("out_shipment_count")),
3,
"Incorrect Out Shipment Count",
) )
self.assertEqual( self.assertEqual(
self.rma_customer_id.in_shipment_count, 1, "Incorrect In Shipment Count" self.rma_customer_id.in_shipment_count, 1, "Incorrect In Shipment Count"
@@ -840,4 +842,41 @@ class TestRma(common.SavepointCase):
) )
for line in self.rma_supplier_id.rma_line_ids: for line in self.rma_supplier_id.rma_line_ids:
line.action_rma_done() line.action_rma_done()
self.assertEqual(line.mapped("state"), ["done"], "Wrong State") self.assertEquals(line.state, "done", "Wrong State")
def test_05_rma_order_line(self):
"""Property rma_customer_operation_id on product or product category
correctly handled inside _onchange_product_id()
"""
rma_operation = self.env["rma.operation"].search([], limit=1)
self.assertTrue(rma_operation)
# Case of product template
self.rma_customer_id.rma_line_ids.mapped("product_id").write(
{"rma_customer_operation_id": rma_operation.id}
)
for line in self.rma_customer_id.rma_line_ids:
data = {"product_id": line.product_id.id}
new_line = self.rma_line.new(data)
self.assertFalse(new_line.operation_id)
self.assertTrue(new_line.product_id.rma_customer_operation_id)
self.assertTrue(new_line.product_id.categ_id.rma_customer_operation_id)
new_line._onchange_product_id()
self.assertEqual(new_line.operation_id, rma_operation)
# Case of product category
self.rma_customer_id.rma_line_ids.mapped("product_id").write(
{"rma_customer_operation_id": False}
)
self.rma_customer_id.rma_line_ids.mapped("product_id.categ_id").write(
{"rma_customer_operation_id": rma_operation.id}
)
for line in self.rma_customer_id.rma_line_ids:
data = {"product_id": line.product_id.id}
new_line = self.rma_line.new(data)
self.assertFalse(new_line.operation_id)
self.assertFalse(new_line.product_id.rma_customer_operation_id)
self.assertTrue(new_line.product_id.categ_id.rma_customer_operation_id)
new_line._onchange_product_id()
self.assertEqual(new_line.operation_id, rma_operation)

View File

@@ -37,7 +37,8 @@ class RmaAddStockMove(models.TransientModel):
domain="[('state', '=', 'done')]", domain="[('state', '=', 'done')]",
) )
show_lot_filter = fields.Boolean( show_lot_filter = fields.Boolean(
string="Show lot filter?", compute="_compute_lot_domain", string="Show lot filter?",
compute="_compute_lot_domain",
) )
lot_domain_ids = fields.Many2many( lot_domain_ids = fields.Many2many(
comodel_name="stock.production.lot", comodel_name="stock.production.lot",

View File

@@ -7,7 +7,10 @@ from odoo import api, fields, models
class PurchaseOrderLine(models.Model): class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line" _inherit = "purchase.order.line"
rma_line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA",) rma_line_id = fields.Many2one(
comodel_name="rma.order.line",
string="RMA",
)
@api.model @api.model
def name_search(self, name="", args=None, operator="ilike", limit=100): def name_search(self, name="", args=None, operator="ilike", limit=100):

View File

@@ -37,7 +37,8 @@ class RmaOrderLine(models.Model):
rec.qty_to_purchase = 0.0 rec.qty_to_purchase = 0.0
purchase_count = fields.Integer( purchase_count = fields.Integer(
compute="_compute_purchase_count", string="# of Purchases", compute="_compute_purchase_count",
string="# of Purchases",
) )
purchase_order_line_id = fields.Many2one( purchase_order_line_id = fields.Many2one(
comodel_name="purchase.order.line", comodel_name="purchase.order.line",

View File

@@ -42,7 +42,8 @@ class RmaAddSale(models.TransientModel):
string="Sale Lines", string="Sale Lines",
) )
show_lot_filter = fields.Boolean( show_lot_filter = fields.Boolean(
string="Show lot filter?", compute="_compute_lot_domain", string="Show lot filter?",
compute="_compute_lot_domain",
) )
lot_domain_ids = fields.Many2many( lot_domain_ids = fields.Many2many(
comodel_name="stock.production.lot", comodel_name="stock.production.lot",
@@ -50,7 +51,9 @@ class RmaAddSale(models.TransientModel):
compute="_compute_lot_domain", compute="_compute_lot_domain",
) )
@api.depends("sale_line_ids.move_ids.move_line_ids.lot_id",) @api.depends(
"sale_line_ids.move_ids.move_line_ids.lot_id",
)
def _compute_lot_domain(self): def _compute_lot_domain(self):
for rec in self: for rec in self:
rec.lot_domain_ids = ( rec.lot_domain_ids = (