mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX]rma: test05 fixed
This commit is contained in:
@@ -46,7 +46,7 @@ repos:
|
||||
- --remove-duplicate-keys
|
||||
- --remove-unused-variables
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 19.10b0
|
||||
rev: 22.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def set_rma_customer_operation_property(cr):
|
||||
"""
|
||||
"""
|
||||
cr.execute(
|
||||
"""
|
||||
WITH rma_customer_operation_id_field AS (
|
||||
SELECT id FROM ir_model_fields WHERE model='product.template' AND name='rma_customer_operation_id'
|
||||
)
|
||||
INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
|
||||
SELECT 'rma_customer_operation_id', 'many2one', rco.id, ro.company_id, CONCAT('product.template,', t.id), CONCAT('rma.operation,', ro.id)
|
||||
FROM product_template t JOIN rma_operation ro ON t.rma_customer_operation_id = ro.id
|
||||
, rma_customer_operation_id_field rco
|
||||
WHERE ro.company_id IS NOT NULL
|
||||
AND NOT EXISTS(SELECT 1
|
||||
FROM ir_property
|
||||
WHERE fields_id=rco.id
|
||||
AND company_id=ro.company_id
|
||||
AND res_id=CONCAT('product.template,', t.id))
|
||||
""")
|
||||
_logger.info("Added %s rma_customer_operation_id_field product properties", cr.rowcount)
|
||||
|
||||
|
||||
def set_rma_supplier_operation_property(cr):
|
||||
"""
|
||||
"""
|
||||
cr.execute(
|
||||
"""
|
||||
WITH rma_supplier_operation_id_field AS (
|
||||
SELECT id FROM ir_model_fields WHERE model='product.template' AND name='rma_supplier_operation_id'
|
||||
)
|
||||
INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
|
||||
SELECT 'rma_supplier_operation_id', 'many2one', rco.id, ro.company_id, CONCAT('product.template,', t.id), CONCAT('rma.operation,', ro.id)
|
||||
FROM product_template t JOIN rma_operation ro ON t.rma_supplier_operation_id = ro.id
|
||||
, rma_supplier_operation_id_field rco
|
||||
WHERE ro.company_id IS NOT NULL
|
||||
AND NOT EXISTS(SELECT 1
|
||||
FROM ir_property
|
||||
WHERE fields_id=rco.id
|
||||
AND company_id=ro.company_id
|
||||
AND res_id=CONCAT('product.template,', t.id))
|
||||
""")
|
||||
_logger.info("Added %s rma_supplier_operation_id_field product properties", cr.rowcount)
|
||||
|
||||
|
||||
def set_rma_customer_operation_category_property(cr):
|
||||
"""
|
||||
"""
|
||||
cr.execute(
|
||||
"""
|
||||
WITH rma_customer_operation_id_field AS (
|
||||
SELECT id FROM ir_model_fields WHERE model='product.category' AND name='rma_customer_operation_id'
|
||||
)
|
||||
INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
|
||||
SELECT 'rma_customer_operation_id', 'many2one', rco.id, ro.company_id, CONCAT('product.category,', pc.id), CONCAT('rma.operation,', ro.id)
|
||||
FROM product_category pc JOIN rma_operation ro ON pc.rma_customer_operation_id = ro.id
|
||||
, rma_customer_operation_id_field rco
|
||||
WHERE ro.company_id IS NOT NULL
|
||||
AND NOT EXISTS(SELECT 1
|
||||
FROM ir_property
|
||||
WHERE fields_id=rco.id
|
||||
AND company_id=ro.company_id
|
||||
AND res_id=CONCAT('product.category,', pc.id))
|
||||
""")
|
||||
_logger.info("Added %s rma_customer_operation_id_field product category properties", cr.rowcount)
|
||||
|
||||
|
||||
def set_rma_supplier_operation_category_property(cr):
|
||||
"""
|
||||
"""
|
||||
cr.execute(
|
||||
"""
|
||||
WITH rma_supplier_operation_id_field AS (
|
||||
SELECT id FROM ir_model_fields WHERE model='product.category' AND name='rma_supplier_operation_id'
|
||||
)
|
||||
INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
|
||||
SELECT 'rma_supplier_operation_id', 'many2one', rco.id, ro.company_id, CONCAT('product.category,', pc.id), CONCAT('rma.operation,', ro.id)
|
||||
FROM product_category pc JOIN rma_operation ro ON pc.rma_supplier_operation_id = ro.id
|
||||
, rma_supplier_operation_id_field rco
|
||||
WHERE ro.company_id IS NOT NULL
|
||||
AND NOT EXISTS(SELECT 1
|
||||
FROM ir_property
|
||||
WHERE fields_id=rco.id
|
||||
AND company_id=ro.company_id
|
||||
AND res_id=CONCAT('product.category,', pc.id))
|
||||
""")
|
||||
_logger.info("Added %s rma_supplier_operation_id_field product category properties", cr.rowcount)
|
||||
|
||||
|
||||
def migrate(cr, version=None):
|
||||
if not version:
|
||||
return
|
||||
set_rma_customer_operation_property(cr)
|
||||
set_rma_supplier_operation_property(cr)
|
||||
set_rma_customer_operation_category_property(cr)
|
||||
set_rma_supplier_operation_category_property(cr)
|
||||
@@ -9,13 +9,14 @@ class ProductTemplate(models.Model):
|
||||
|
||||
rma_customer_operation_id = fields.Many2one(
|
||||
company_dependent=True,
|
||||
comodel_name="rma.operation", string="Default RMA Customer Operation"
|
||||
comodel_name="rma.operation",
|
||||
string="Default RMA Customer Operation",
|
||||
)
|
||||
rma_supplier_operation_id = fields.Many2one(
|
||||
company_dependent=True,
|
||||
comodel_name="rma.operation", string="Default RMA Supplier Operation"
|
||||
comodel_name="rma.operation",
|
||||
string="Default RMA Supplier Operation",
|
||||
)
|
||||
rma_approval_policy = fields.Selection(
|
||||
related="categ_id.rma_approval_policy", readonly=True
|
||||
)
|
||||
|
||||
|
||||
@@ -20,9 +20,11 @@ class ProductCategory(models.Model):
|
||||
)
|
||||
rma_customer_operation_id = fields.Many2one(
|
||||
company_dependent=True,
|
||||
comodel_name="rma.operation", string="Default RMA Customer Operation"
|
||||
comodel_name="rma.operation",
|
||||
string="Default RMA Customer Operation",
|
||||
)
|
||||
rma_supplier_operation_id = fields.Many2one(
|
||||
company_dependent=True,
|
||||
comodel_name="rma.operation", string="Default RMA Supplier Operation"
|
||||
comodel_name="rma.operation",
|
||||
string="Default RMA Supplier Operation",
|
||||
)
|
||||
|
||||
@@ -194,8 +194,7 @@ class RmaOrder(models.Model):
|
||||
return self._view_shipments(result, shipments)
|
||||
|
||||
def _get_valid_lines(self):
|
||||
""":return: A recordset of rma lines.
|
||||
"""
|
||||
""":return: A recordset of rma lines."""
|
||||
self.ensure_one()
|
||||
return self.rma_line_ids
|
||||
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import test_rma
|
||||
from . import test_migrations
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import imp
|
||||
import os
|
||||
|
||||
from odoo.modules import get_module_resource
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import file_open
|
||||
|
||||
|
||||
class TestMigrations(TransactionCase):
|
||||
def test_migration_12_0_3_0_0(self):
|
||||
"""Test the migration scripts to 12.0.3.0.0 """
|
||||
|
||||
# Recreate pre-migration condition
|
||||
self.env.cr.execute("""
|
||||
ALTER TABLE product_template
|
||||
ADD COLUMN IF NOT EXISTS rma_customer_operation_id INTEGER """)
|
||||
self.env.cr.execute("""
|
||||
ALTER TABLE product_template
|
||||
ADD COLUMN IF NOT EXISTS rma_supplier_operation_id INTEGER """)
|
||||
self.env.cr.execute("""
|
||||
ALTER TABLE product_category
|
||||
ADD COLUMN IF NOT EXISTS rma_customer_operation_id INTEGER """)
|
||||
self.env.cr.execute("""
|
||||
ALTER TABLE product_category
|
||||
ADD COLUMN IF NOT EXISTS rma_supplier_operation_id INTEGER """)
|
||||
|
||||
rma_operation = self.env["rma.operation"].search([], limit=1)
|
||||
self.env.cr.execute(
|
||||
"UPDATE product_template SET rma_customer_operation_id = %d" % rma_operation.id
|
||||
)
|
||||
self.env.cr.execute(
|
||||
"UPDATE product_template SET rma_supplier_operation_id = %d" % rma_operation.id
|
||||
)
|
||||
self.env.cr.execute(
|
||||
"UPDATE product_category SET rma_customer_operation_id = %d" % rma_operation.id
|
||||
)
|
||||
self.env.cr.execute(
|
||||
"UPDATE product_category SET rma_supplier_operation_id = %d" % rma_operation.id
|
||||
)
|
||||
|
||||
# Properties are not set
|
||||
product = self.env.ref("product.product_product_5")
|
||||
product_tmpl = product.product_tmpl_id
|
||||
product_categ = product.categ_id
|
||||
self.assertFalse(product_tmpl.rma_customer_operation_id)
|
||||
self.assertFalse(product_tmpl.rma_supplier_operation_id)
|
||||
self.assertFalse(product_categ.rma_customer_operation_id)
|
||||
self.assertFalse(product_categ.rma_supplier_operation_id)
|
||||
|
||||
# Run the migration script
|
||||
pyfile = get_module_resource(
|
||||
"rma", "migrations", "12.0.3.0.0", "post-migration.py")
|
||||
name, ext = os.path.splitext(os.path.basename(pyfile))
|
||||
fp, pathname = file_open(pyfile, pathinfo=True)
|
||||
mod = imp.load_module(name, fp, pathname, (".py", "r", imp.PY_SOURCE))
|
||||
mod.migrate(self.env.cr, "12.0.2.3.0")
|
||||
|
||||
# Properties are set
|
||||
product_tmpl.refresh()
|
||||
product_categ.refresh()
|
||||
self.assertEqual(product_tmpl.rma_customer_operation_id, rma_operation)
|
||||
self.assertEqual(product_tmpl.rma_supplier_operation_id, rma_operation)
|
||||
self.assertEqual(product_categ.rma_customer_operation_id, rma_operation)
|
||||
self.assertEqual(product_categ.rma_supplier_operation_id, rma_operation)
|
||||
@@ -425,7 +425,9 @@ class TestRma(common.SavepointCase):
|
||||
sum(lines.mapped("in_shipment_count")), 3, "Incorrect In Shipment Count"
|
||||
)
|
||||
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.rma_customer_id.in_shipment_count, 1, "Incorrect In Shipment Count"
|
||||
@@ -840,8 +842,7 @@ class TestRma(common.SavepointCase):
|
||||
)
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
line.action_rma_done()
|
||||
self.assertEquals(line.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
|
||||
@@ -851,28 +852,28 @@ class TestRma(common.SavepointCase):
|
||||
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})
|
||||
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}
|
||||
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.assertFalse(new_line.product_id.categ_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})
|
||||
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}
|
||||
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)
|
||||
|
||||
@@ -37,7 +37,8 @@ class RmaAddStockMove(models.TransientModel):
|
||||
domain="[('state', '=', 'done')]",
|
||||
)
|
||||
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(
|
||||
comodel_name="stock.production.lot",
|
||||
|
||||
@@ -7,7 +7,10 @@ from odoo import api, fields, models
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_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
|
||||
def name_search(self, name="", args=None, operator="ilike", limit=100):
|
||||
|
||||
@@ -37,7 +37,8 @@ class RmaOrderLine(models.Model):
|
||||
rec.qty_to_purchase = 0.0
|
||||
|
||||
purchase_count = fields.Integer(
|
||||
compute="_compute_purchase_count", string="# of Purchases",
|
||||
compute="_compute_purchase_count",
|
||||
string="# of Purchases",
|
||||
)
|
||||
purchase_order_line_id = fields.Many2one(
|
||||
comodel_name="purchase.order.line",
|
||||
|
||||
@@ -42,7 +42,8 @@ class RmaAddSale(models.TransientModel):
|
||||
string="Sale Lines",
|
||||
)
|
||||
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(
|
||||
comodel_name="stock.production.lot",
|
||||
@@ -50,7 +51,9 @@ class RmaAddSale(models.TransientModel):
|
||||
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):
|
||||
for rec in self:
|
||||
rec.lot_domain_ids = (
|
||||
|
||||
Reference in New Issue
Block a user