Skip to content

Commit

Permalink
[MIG] rma_purchase: Migration to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosVForgeFlow authored and AaronHForgeFlow committed May 6, 2024
1 parent cb5dabf commit 79c27f0
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion rma_purchase/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
{
"name": "RMA Purchase",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "RMA",
"summary": "RMA from PO",
"license": "LGPL-3",
Expand Down
8 changes: 4 additions & 4 deletions rma_purchase/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class AccountMove(models.Model):
_inherit = "account.move"

def _prepare_invoice_line_from_rma_line(self, line):
data = super(AccountMove, self)._prepare_invoice_line_from_rma_line(line)
data = super()._prepare_invoice_line_from_rma_line(line)
if line.purchase_order_line_id:
data["purchase_line_id"]: line.purchase_order_line_id.id
data["purchase_line_id"] = line.purchase_order_line_id.id
return data

def action_post(self):
res = super(AccountMove, self).action_post()
res = super().action_post()
for move in self:
rma_mls = move.line_ids.filtered(lambda l: l.rma_line_id)
rma_mls = move.line_ids.filtered(lambda x: x.rma_line_id)
if rma_mls:
# Try to reconcile the interim accounts for RMA lines
rmas = rma_mls.mapped("rma_line_id")
Expand Down
2 changes: 1 addition & 1 deletion rma_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PurchaseOrder(models.Model):
@api.model
def new(self, vals, origin=None, ref=None):
"""Allows to propose a line based on the RMA information."""
res = super(PurchaseOrder, self).new(vals)
res = super().new(vals)
rma_line_id = self.env.context.get("rma_line_id")
if rma_line_id:
rma_line = self.env["rma.order.line"].browse(rma_line_id)
Expand Down
24 changes: 11 additions & 13 deletions rma_purchase/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ def name_search(self, name="", args=None, operator="ilike", limit=100):
(self._rec_name, operator, name),
("order_id.name", operator, name),
]
return super(PurchaseOrderLine, self).name_search(
name=name, args=args, operator=operator, limit=limit
)
return super().name_search(name=name, args=args, operator=operator, limit=limit)

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
):
"""Typed text is cleared here for better extensibility."""
return super(PurchaseOrderLine, self)._name_search(
return super()._name_search(
name="",
args=args,
operator=operator,
Expand All @@ -50,8 +48,7 @@ def name_get(self):
res.append(
(
purchase.id,
"%s %s %s qty:%s"
% (
"{} {} {} qty:{}".format(
purchase.order_id.name,
" ".join(
str(x)
Expand All @@ -68,11 +65,12 @@ def name_get(self):
res.append(super(PurchaseOrderLine, purchase).name_get()[0])
return res
else:
return super(PurchaseOrderLine, self).name_get()
return super().name_get()

@api.model
def create(self, vals):
rma_line_id = self.env.context.get("rma_line_id")
if rma_line_id:
vals["rma_line_id"] = rma_line_id
return super(PurchaseOrderLine, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
rma_line_id = self.env.context.get("rma_line_id")
if rma_line_id:
vals["rma_line_id"] = rma_line_id
return super().create(vals_list)
10 changes: 4 additions & 6 deletions rma_purchase/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def _compute_qty_purchase(self):
comodel_name="purchase.order.line",
string="Originating Purchase Line",
ondelete="restrict",
readonly=True,
states={"draft": [("readonly", False)]},
)
purchase_id = fields.Many2one(
string="Source Purchase Order",
Expand Down Expand Up @@ -92,7 +90,7 @@ def _compute_qty_purchase(self):
def _onchange_product_id(self):
"""Domain for purchase_order_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"):
res["domain"] = {}
domain = [
Expand All @@ -107,7 +105,7 @@ def _onchange_product_id(self):

@api.onchange("operation_id")
def _onchange_operation_id(self):
res = super(RmaOrderLine, self)._onchange_operation_id()
res = super()._onchange_operation_id()
if self.operation_id:
self.purchase_policy = self.operation_id.purchase_policy or "no"
return res
Expand Down Expand Up @@ -202,7 +200,7 @@ def _check_purchase_partner(self):
)

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 == "purchase_order_line_id":
self.purchase_order_line_id = False
return res
Expand Down Expand Up @@ -233,7 +231,7 @@ def _get_rma_purchased_qty(self):

def _get_price_unit(self):
self.ensure_one()
price_unit = super(RmaOrderLine, self)._get_price_unit()
price_unit = super()._get_price_unit()
if self.purchase_order_line_id:
moves = self.purchase_order_line_id.move_ids
if moves:
Expand Down
2 changes: 1 addition & 1 deletion rma_purchase/tests/test_rma_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestRmaPurchase(common.TransactionCase):
def setUp(self):
super(TestRmaPurchase, self).setUp()
super().setUp()

self.rma_obj = self.env["rma.order"]
self.rma_line_obj = self.env["rma.order.line"]
Expand Down
2 changes: 1 addition & 1 deletion rma_purchase/tests/test_rma_stock_account_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TestRmaStockAccountPurchase(TestRmaStockAccount):
@classmethod
def setUpClass(cls):
super(TestRmaStockAccountPurchase, cls).setUpClass()
super().setUpClass()
cls.pol_model = cls.env["purchase.order.line"]
cls.po_model = cls.env["purchase.order"]
cls.rma_operation_supplier_refund = cls.env.ref(
Expand Down
18 changes: 8 additions & 10 deletions rma_purchase/views/rma_order_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
name="%(action_rma_order_line_make_purchase_order)d"
string="Create Purchase Order"
class="oe_highlight"
attrs="{'invisible':['|', ('qty_to_purchase', '=', 0), ('state', '!=', 'approved')]}"
context="{'rma_line_id': active_id, 'default_partner_id': partner_id}"
invisible="qty_to_purchase == 0 or state != 'approved'"
context="{'rma_line_id': id, 'default_partner_id': partner_id}"
type="action"
/>
<button
name="%(action_rma_order_line_make_purchase_order)d"
string="Create Purchase Order"
attrs="{'invisible':['|', ('qty_to_purchase', '!=', 0), ('state', '!=', 'approved')]}"
context="{'rma_line_id': active_id, 'default_partner_id': partner_id}"
invisible="qty_to_purchase != 0 or state != 'approved'"
context="{'rma_line_id': id, 'default_partner_id': partner_id}"
type="action"
/>
</header>
Expand All @@ -37,7 +37,7 @@
class="oe_stat_button"
icon="fa-shopping-cart"
groups="purchase.group_purchase_user"
attrs="{'invisible':[('purchase_count','=',0)]}"
invisible="purchase_count == 0"
>
<field
name="purchase_count"
Expand All @@ -54,10 +54,11 @@
domain="['|',
('order_id.partner_id', '=', partner_id),
('order_id.partner_id', 'child_of', partner_id)]"
readonly="state not in ['draft']"
/>
</group>
<group name="quantities" position="inside">
<group attrs="{'invisible': [('purchase_policy', '=', 'no')]}">
<group invisible="purchase_policy == 'no'">
<field name="qty_to_purchase" />
<field name="qty_purchased" />
</group>
Expand All @@ -66,10 +67,7 @@
<field name="purchase_policy" />
</field>
<field name="origin" position="after">
<field
name="purchase_id"
attrs="{'invisible': [('purchase_order_line_id', '=', False)]}"
/>
<field name="purchase_id" invisible="purchase_order_line_id == False" />
</field>
<notebook position="inside">
<page name="purchase" string="Purchase Lines">
Expand Down
2 changes: 1 addition & 1 deletion rma_purchase/wizards/rma_add_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RmaAddPurchase(models.TransientModel):

@api.model
def default_get(self, fields_list):
res = super(RmaAddPurchase, self).default_get(fields_list)
res = super().default_get(fields_list)
rma_obj = self.env["rma.order"]
rma_id = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
Expand Down
4 changes: 2 additions & 2 deletions rma_purchase/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RmaMakePicking(models.TransientModel):
_inherit = "rma_make_picking.wizard"

def _prepare_item(self, line):
res = super(RmaMakePicking, self)._prepare_item(line)
res = super()._prepare_item(line)
res["purchase_order_line_id"] = line.purchase_order_line_id.id
return res

Expand All @@ -24,7 +24,7 @@ def _get_action(self, pickings, procurements):
result["domain"] = [("id", "in", po_list)]
return result
else:
action = super(RmaMakePicking, self)._get_action(pickings, procurements)
action = super()._get_action(pickings, procurements)
return action


Expand Down
4 changes: 2 additions & 2 deletions rma_purchase/wizards/rma_order_line_make_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RmaLineMakePurchaseOrder(models.TransientModel):
partner_id = fields.Many2one(
comodel_name="res.partner",
required=False,
readonly=1,
readonly=True,
)
item_ids = fields.One2many(
comodel_name="rma.order.line.make.purchase.order.item",
Expand Down Expand Up @@ -42,7 +42,7 @@ def _prepare_item(self, line):

@api.model
def default_get(self, fields_list):
res = super(RmaLineMakePurchaseOrder, self).default_get(fields_list)
res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
Expand Down
4 changes: 2 additions & 2 deletions rma_purchase/wizards/rma_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RmaRefund(models.TransientModel):
_inherit = "rma.refund"

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.type == "supplier":
if rma.account_move_line_id:
price_unit = rma.account_move_line_id.price_unit
Expand All @@ -17,7 +17,7 @@ def _get_refund_price_unit(self, rma):
return price_unit

def _get_refund_currency(self, rma):
currency = super(RmaRefund, self)._get_refund_currency(rma)
currency = super()._get_refund_currency(rma)
if rma.type == "supplier":
if rma.account_move_line_id:
currency = rma.account_move_line_id.currency_id
Expand Down

0 comments on commit 79c27f0

Please sign in to comment.