[MIG] rma_sale: Migration to v17

This commit is contained in:
Carlos Vallés Fuster
2024-05-06 16:20:25 +02:00
committed by JasminSForgeFlow
parent 7a823ab020
commit 6d5abdde93
15 changed files with 42 additions and 49 deletions

View File

@@ -3,7 +3,7 @@
{ {
"name": "RMA Sale", "name": "RMA Sale",
"version": "16.0.1.0.0", "version": "17.0.1.0.0",
"license": "LGPL-3", "license": "LGPL-3",
"category": "RMA", "category": "RMA",
"summary": "Links RMA with Sales Orders", "summary": "Links RMA with Sales Orders",

View File

@@ -18,7 +18,7 @@ class StockRule(models.Model):
company_id, company_id,
values, values,
): ):
res = super(StockRule, self)._get_stock_move_values( res = super()._get_stock_move_values(
product_id, product_id,
product_qty, product_qty,
product_uom, product_uom,

View File

@@ -27,7 +27,7 @@ class RmaOrder(models.Model):
("sale_line_id", "=", line.sale_line_id.id), ("sale_line_id", "=", line.sale_line_id.id),
] ]
else: else:
domain = super(RmaOrder, self)._get_line_domain(rma_id, line) domain = super()._get_line_domain(rma_id, line)
return domain return domain
def action_view_sale_order(self): def action_view_sale_order(self):

View File

@@ -42,8 +42,6 @@ class RmaOrderLine(models.Model):
string="Originating Sales Order Line", string="Originating Sales Order Line",
ondelete="restrict", ondelete="restrict",
copy=False, copy=False,
readonly=True,
states={"draft": [("readonly", False)]},
) )
sale_id = fields.Many2one( sale_id = fields.Many2one(
string="Source Sales Order", related="sale_line_id.order_id" string="Source Sales Order", related="sale_line_id.order_id"
@@ -52,8 +50,6 @@ class RmaOrderLine(models.Model):
comodel_name="sale.order.line", comodel_name="sale.order.line",
inverse_name="rma_line_id", inverse_name="rma_line_id",
string="Sales Order Lines", string="Sales Order Lines",
readonly=True,
states={"draft": [("readonly", False)]},
copy=False, copy=False,
) )
qty_to_sell = fields.Float( qty_to_sell = fields.Float(
@@ -85,7 +81,7 @@ class RmaOrderLine(models.Model):
@api.onchange("product_id", "partner_id") @api.onchange("product_id", "partner_id")
def _onchange_product_id(self): def _onchange_product_id(self):
"""Domain for sale_line_id is computed here to make it dynamic.""" """Domain for sale_line_id is computed here to make it dynamic."""
res = super(RmaOrderLine, self)._onchange_product_id() res = super()._onchange_product_id()
if not res.get("domain"): if not res.get("domain"):
res["domain"] = {} res["domain"] = {}
domain = [ domain = [
@@ -100,7 +96,7 @@ class RmaOrderLine(models.Model):
@api.onchange("operation_id") @api.onchange("operation_id")
def _onchange_operation_id(self): def _onchange_operation_id(self):
res = super(RmaOrderLine, self)._onchange_operation_id() res = super()._onchange_operation_id()
if self.operation_id: if self.operation_id:
self.sale_policy = self.operation_id.sale_policy or "no" self.sale_policy = self.operation_id.sale_policy or "no"
return res return res
@@ -173,7 +169,7 @@ class RmaOrderLine(models.Model):
self._remove_other_data_origin("sale_line_id") self._remove_other_data_origin("sale_line_id")
def _remove_other_data_origin(self, exception): def _remove_other_data_origin(self, exception):
res = super(RmaOrderLine, self)._remove_other_data_origin(exception) res = super()._remove_other_data_origin(exception)
if not exception == "sale_line_id": if not exception == "sale_line_id":
self.sale_line_id = False self.sale_line_id = False
return res return res
@@ -224,7 +220,7 @@ class RmaOrderLine(models.Model):
def _get_price_unit(self): def _get_price_unit(self):
self.ensure_one() self.ensure_one()
price_unit = super(RmaOrderLine, self)._get_price_unit() price_unit = super()._get_price_unit()
if self.sale_line_id: if self.sale_line_id:
moves = self.sale_line_id.move_ids.filtered( moves = self.sale_line_id.move_ids.filtered(
lambda x: x.state == "done" lambda x: x.state == "done"

View File

@@ -16,16 +16,14 @@ class SaleOrderLine(models.Model):
(self._rec_name, operator, name), (self._rec_name, operator, name),
("order_id.name", operator, name), ("order_id.name", operator, name),
] ]
return super(SaleOrderLine, self).name_search( return super().name_search(name=name, args=args, operator=operator, limit=limit)
name=name, args=args, operator=operator, limit=limit
)
@api.model @api.model
def _name_search( def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
): ):
"""Typed text is cleared here for better extensibility.""" """Typed text is cleared here for better extensibility."""
return super(SaleOrderLine, self)._name_search( return super()._name_search(
name="", name="",
args=args, args=args,
operator=operator, operator=operator,
@@ -35,7 +33,7 @@ class SaleOrderLine(models.Model):
def _get_sale_line_rma_name_get_label(self): def _get_sale_line_rma_name_get_label(self):
self.ensure_one() self.ensure_one()
return "SO:%s | INV: %s, | PART:%s | QTY:%s" % ( return "SO:{} | INV: {}, | PART:{} | QTY:{}".format(
self.order_id.name, self.order_id.name,
" ".join(str(x) for x in [inv.name for inv in self.order_id.invoice_ids]), " ".join(str(x) for x in [inv.name for inv in self.order_id.invoice_ids]),
self.product_id.name, self.product_id.name,
@@ -61,8 +59,6 @@ class SaleOrderLine(models.Model):
) )
def _prepare_order_line_procurement(self, group_id=False): def _prepare_order_line_procurement(self, group_id=False):
vals = super(SaleOrderLine, self)._prepare_order_line_procurement( vals = super()._prepare_order_line_procurement(group_id=group_id)
group_id=group_id
)
vals.update({"rma_line_id": self.rma_line_id.id}) vals.update({"rma_line_id": self.rma_line_id.id})
return vals return vals

View File

@@ -7,7 +7,7 @@ from odoo.tests import common
class TestRmaSale(common.SingleTransactionCase): class TestRmaSale(common.SingleTransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestRmaSale, cls).setUpClass() super().setUpClass()
cls.rma_obj = cls.env["rma.order"] cls.rma_obj = cls.env["rma.order"]
cls.rma_line_obj = cls.env["rma.order.line"] cls.rma_line_obj = cls.env["rma.order.line"]
@@ -62,7 +62,6 @@ class TestRmaSale(common.SingleTransactionCase):
}, },
), ),
], ],
"pricelist_id": cls.env.ref("product.list0").id,
} }
) )

View File

@@ -10,7 +10,7 @@ from odoo.addons.rma_account.tests.test_rma_stock_account import TestRmaStockAcc
class TestRmaStockAccountSale(TestRmaStockAccount): class TestRmaStockAccountSale(TestRmaStockAccount):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestRmaStockAccountSale, cls).setUpClass() super().setUpClass()
cls.operation_receive_refund = cls.env.ref( cls.operation_receive_refund = cls.env.ref(
"rma_account.rma_operation_customer_refund" "rma_account.rma_operation_customer_refund"
) )
@@ -35,12 +35,12 @@ class TestRmaStockAccountSale(TestRmaStockAccount):
}, },
), ),
], ],
"pricelist_id": cls.env.ref("product.list0").id,
} }
) )
cls.so1.action_confirm() cls.so1.action_confirm()
for ml in cls.so1.picking_ids.move_line_ids: for ml in cls.so1.picking_ids.move_line_ids:
ml.qty_done = ml.reserved_uom_qty ml.quantity = ml.quantity_product_uom
ml.picked = True
cls.so1.picking_ids.button_validate() cls.so1.picking_ids.button_validate()
def test_01_cost_from_so_move(self): def test_01_cost_from_so_move(self):

View File

@@ -12,7 +12,7 @@
name="action_view_origin_sale_order" name="action_view_origin_sale_order"
class="oe_stat_button" class="oe_stat_button"
icon="fa-strikethrough" icon="fa-strikethrough"
attrs="{'invisible': [('sale_id', '=', False)]}" invisible="sale_id == False"
string="Origin Sale Order" string="Origin Sale Order"
> >
</button> </button>
@@ -21,7 +21,7 @@
name="action_view_sale_order" name="action_view_sale_order"
class="oe_stat_button" class="oe_stat_button"
icon="fa-strikethrough" icon="fa-strikethrough"
attrs="{'invisible': [('sales_count', '=', 0)]}" invisible="sales_count == 0"
groups="sales_team.group_sale_salesman_all_leads" groups="sales_team.group_sale_salesman_all_leads"
> >
<field <field
@@ -37,11 +37,12 @@
name="sale_line_id" name="sale_line_id"
context="{'rma': True}" context="{'rma': True}"
options="{'no_create': True}" options="{'no_create': True}"
attrs="{'invisible':[('type', '!=', 'customer')]}" invisible="type != 'customer'"
readonly="state != 'draft'"
/> />
</group> </group>
<group name="quantities" position="inside"> <group name="quantities" position="inside">
<group attrs="{'invisible': [('sale_policy', '=', 'no')]}"> <group invisible="sale_policy == 'no'">
<field name="qty_to_sell" /> <field name="qty_to_sell" />
<field name="qty_sold" /> <field name="qty_sold" />
</group> </group>
@@ -53,9 +54,13 @@
<page <page
name="sale" name="sale"
string="Sale Lines" string="Sale Lines"
attrs="{'invisible': [('sale_line_ids', '=', [])]}" invisible="sale_line_ids == []"
> >
<field name="sale_line_ids" nolabel="1" /> <field
name="sale_line_ids"
nolabel="1"
readonly="state != 'draft'"
/>
</page> </page>
</notebook> </notebook>
</field> </field>
@@ -71,13 +76,13 @@
name="%(action_rma_order_line_make_sale_order)d" name="%(action_rma_order_line_make_sale_order)d"
string="Create Sales Quotation" string="Create Sales Quotation"
class="oe_highlight" class="oe_highlight"
attrs="{'invisible':['|', '|', '|', ('qty_to_sell', '=', 0), ('qty_to_sell', '&lt;', 0), ('state', '!=', 'approved'), ('sale_policy', '=', 'no')]}" invisible="qty_to_sell == 0 or qty_to_sell &lt; 0 or state != 'approved' or sale_policy == 'no'"
type="action" type="action"
/> />
<button <button
name="%(action_rma_order_line_make_sale_order)d" name="%(action_rma_order_line_make_sale_order)d"
string="Create Sales Quotation" string="Create Sales Quotation"
attrs="{'invisible':['|', '|', ('qty_to_sell', '>', 0), ('state', '!=', 'approved'), ('sale_policy', '=', 'no')]}" invisible="qty_to_sell &gt; 0 or state != 'approved' or sale_policy == 'no'"
type="action" type="action"
/> />
</header> </header>

View File

@@ -12,7 +12,7 @@
class="oe_stat_button" class="oe_stat_button"
icon="fa-pencil-square-o" icon="fa-pencil-square-o"
groups="sales_team.group_sale_salesman" groups="sales_team.group_sale_salesman"
attrs="{'invisible':[('type', '!=', 'customer')]}" invisible="type != 'customer'"
> >
<field name="sale_count" widget="statinfo" string="Origin SO" /> <field name="sale_count" widget="statinfo" string="Origin SO" />
</button> </button>

View File

@@ -35,7 +35,7 @@
name="action_view_rma" name="action_view_rma"
class="oe_stat_button" class="oe_stat_button"
icon="fa-dropbox" icon="fa-dropbox"
attrs="{'invisible': [('rma_count', '=', 0)]}" invisible="rma_count == 0"
groups="rma.group_rma_customer_user" groups="rma.group_rma_customer_user"
> >
<field name="rma_count" widget="statinfo" string="RMA" /> <field name="rma_count" widget="statinfo" string="RMA" />

View File

@@ -11,7 +11,7 @@ class RmaAddSale(models.TransientModel):
@api.model @api.model
def default_get(self, fields_list): def default_get(self, fields_list):
res = super(RmaAddSale, self).default_get(fields_list) res = super().default_get(fields_list)
rma_obj = self.env["rma.order"] rma_obj = self.env["rma.order"]
rma_id = self.env.context["active_ids"] or [] rma_id = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"] active_model = self.env.context["active_model"]
@@ -197,8 +197,8 @@ class RmaAddSale(models.TransientModel):
rec = rma_line_obj.create(data) rec = rma_line_obj.create(data)
# Ensure that configuration on the operation is applied # Ensure that configuration on the operation is applied
# TODO MIG: in v16 the usage of such onchange can be removed in # TODO MIG: in v16 the usage of such onchange can be removed in
# favor of (pre)computed stored editable fields for all policies # favor of (pre)computed stored editable fields for all
# and configuration in the RMA operation. # policies and configuration in the RMA operation.
rec._onchange_operation_id() rec._onchange_operation_id()
rec.price_unit = rec._get_price_unit() rec.price_unit = rec._get_price_unit()
rma = self.rma_id rma = self.rma_id

View File

@@ -44,23 +44,20 @@
</field> </field>
<field name="show_lot_filter" invisible="1" /> <field name="show_lot_filter" invisible="1" />
<field name="lot_domain_ids" widget="many2many_tags" invisible="1" /> <field name="lot_domain_ids" widget="many2many_tags" invisible="1" />
<div <div class="oe_grey" invisible="show_lot_filter == False">
class="oe_grey"
attrs="{'invisible': [('show_lot_filter', '=', False)]}"
>
The creation of the RMA Lines will be separated according to the lots or serials selected The creation of the RMA Lines will be separated according to the lots or serials selected
</div> </div>
<div class="o_row"> <div class="o_row">
<label <label
for="lot_ids" for="lot_ids"
attrs="{'invisible': [('show_lot_filter', '=', False)]}" invisible="show_lot_filter == False"
string="Selected Lot/Serial Numbers" string="Selected Lot/Serial Numbers"
/> />
<field <field
name="lot_ids" name="lot_ids"
widget="many2many_tags" widget="many2many_tags"
domain="[('id', 'in', lot_domain_ids)]" domain="[('id', 'in', lot_domain_ids)]"
attrs="{'invisible': [('show_lot_filter', '=', False)]}" invisible="show_lot_filter == False"
options="{'no_create': True}" options="{'no_create': True}"
/> />
<button <button
@@ -68,7 +65,7 @@
type="object" type="object"
string="Select all" string="Select all"
class="oe_inline" class="oe_inline"
attrs="{'invisible': [('show_lot_filter', '=', False)]}" invisible="show_lot_filter == False"
/> />
</div> </div>
<footer> <footer>
@@ -114,7 +111,7 @@
name="%(action_rma_add_sale)d" name="%(action_rma_add_sale)d"
string="Add From Sale Order" string="Add From Sale Order"
type="action" type="action"
attrs="{'invisible':[('type', '!=', 'customer')]}" invisible="type != 'customer'"
/> />
</xpath> </xpath>
</field> </field>

View File

@@ -8,7 +8,7 @@ class RmaMakePicking(models.TransientModel):
@api.returns("rma.order.line") @api.returns("rma.order.line")
def _prepare_item(self, line): def _prepare_item(self, line):
res = super(RmaMakePicking, self)._prepare_item(line) res = super()._prepare_item(line)
res["sale_line_id"] = line.sale_line_id.id res["sale_line_id"] = line.sale_line_id.id
return res return res

View File

@@ -43,7 +43,7 @@ class RmaLineMakeSaleOrder(models.TransientModel):
@api.model @api.model
def default_get(self, fields_list): def default_get(self, fields_list):
res = super(RmaLineMakeSaleOrder, self).default_get(fields_list) res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"] rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or [] rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"] active_model = self.env.context["active_model"]

View File

@@ -8,12 +8,12 @@ class RmaRefund(models.TransientModel):
@api.returns("rma.order.line") @api.returns("rma.order.line")
def _prepare_item(self, line): def _prepare_item(self, line):
res = super(RmaRefund, self)._prepare_item(line) res = super()._prepare_item(line)
res["sale_line_id"] = line.sale_line_id.id res["sale_line_id"] = line.sale_line_id.id
return res return res
def _get_refund_price_unit(self, rma): def _get_refund_price_unit(self, rma):
price_unit = super(RmaRefund, self)._get_refund_price_unit(rma) price_unit = super()._get_refund_price_unit(rma)
if rma.operation_id.refund_free_of_charge: if rma.operation_id.refund_free_of_charge:
return price_unit return price_unit
if rma.type == "customer": if rma.type == "customer":