Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] rma_sale: create rma group from sale order #441

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions rma_sale/wizards/rma_add_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ class RmaAddSale(models.TransientModel):
@api.model
def default_get(self, fields_list):
res = super(RmaAddSale, self).default_get(fields_list)
rma_obj = self.env["rma.order"]
rma_id = self.env.context["active_ids"] or []
active_id = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
if not rma_id:
if not active_id:
return res
assert active_model == "rma.order", "Bad context propagation"
assert active_model in ["rma.order", "sale.order"], "Bad context propagation"

if active_model == "rma.order":
rma = self.env["rma.order"].browse(active_id)
res["rma_id"] = rma.id
res["partner_id"] = rma.partner_id.id
res["sale_id"] = False
res["sale_line_ids"] = False
elif active_model == "sale.order":
sale = self.env["sale.order"].browse(active_id)
res["rma_id"] = False
res["partner_id"] = sale.partner_id.id
res["sale_id"] = sale.id
res["sale_line_ids"] = False

rma = rma_obj.browse(rma_id)
res["rma_id"] = rma.id
res["partner_id"] = rma.partner_id.id
res["sale_id"] = False
res["sale_line_ids"] = False
return res

rma_id = fields.Many2one(
Expand Down Expand Up @@ -167,7 +174,21 @@ def _get_existing_sale_lines(self):
existing_sale_lines.append(rma_line.sale_line_id)
return existing_sale_lines

def _prepare_rma_from_sale_order(self):

return {
"partner_id": self.partner_id.id,
"company_id": self.sale_id.company_id.id,
"in_warehouse_id": self.sale_id.warehouse_id.id,
"type": "customer",
}

def add_lines(self):
redirect_to_rma = False
if not self.rma_id:
redirect_to_rma = True
vals = self._prepare_rma_from_sale_order()
self.rma_id = self.env["rma.order"].create(vals)
rma_line_obj = self.env["rma.order.line"]
existing_sale_lines = self._get_existing_sale_lines()
for line in self.sale_line_ids:
Expand Down Expand Up @@ -198,4 +219,7 @@ def add_lines(self):
rma = self.rma_id
data_rma = self._get_rma_data()
rma.write(data_rma)
return {"type": "ir.actions.act_window_close"}
if self.env.context["active_model"] == "rma.order":
return {"type": "ir.actions.act_window_close"}
elif redirect_to_rma:
return self.rma_id.get_formview_action()
12 changes: 12 additions & 0 deletions rma_sale/wizards/rma_add_sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@
</record>


<record id="action_view_rma_sale" model="ir.actions.act_window">
<field name="name">Create RMA</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">rma_add_sale</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="view_rma_add_sale" />
<field name="binding_model_id" ref="sale.model_sale_order" />
<field name="context"> {}
</field>
</record>

<record id="view_rma_add_sale_form" model="ir.ui.view">
<field name="name">rma.order.form - sale wizard</field>
<field name="model">rma.order</field>
Expand Down