[FIX]rma_account test + adding from existing invoice

This commit is contained in:
ahenriquez
2020-02-14 13:15:14 +01:00
parent b82295206d
commit 3cce78ed84
6 changed files with 133 additions and 138 deletions

View File

@@ -91,33 +91,27 @@ class RmaOrder(models.Model):
return res
def action_view_invoice_refund(self):
action = self.env.ref("account.action_invoice_tree2")
result = action.read()[0]
move_ids = self.mapped("rma_line_ids.refund_line_ids.move_id").ids
if move_ids:
# choose the view_mode accordingly
if len(move_ids) > 1:
result["domain"] = [("id", "in", move_ids)]
else:
res = self.env.ref("account.move_supplier_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = move_ids[0]
return result
move_ids = self.mapped("rma_line_ids.move_id").ids
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)
return {
"domain": [("id", "in", move_ids)],
"name": "Refunds",
"res_model": "account.move",
"type": "ir.actions.act_window",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}
def action_view_invoice(self):
if self.type == "supplier":
action = self.env.ref("account.action_invoice_tree2")
res = self.env.ref("account.move_supplier_form", False)
else:
action = self.env.ref("account.action_invoice_tree")
res = self.env.ref("account.view_move_form", False)
result = action.read()[0]
move_ids = self.mapped("rma_line_ids.move_id").ids
if move_ids:
# choose the view_mode accordingly
if len(move_ids) > 1:
result["domain"] = [("id", "in", move_ids)]
else:
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = move_ids[0]
return result
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)
return {
"domain": [("id", "in", move_ids)],
"name": "Originating Invoice",
"res_model": "account.move",
"type": "ir.actions.act_window",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}

View File

@@ -4,8 +4,6 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.addons import decimal_precision as dp
class RmaOrderLine(models.Model):
_inherit = "rma.order.line"
@@ -24,7 +22,7 @@ class RmaOrderLine(models.Model):
for rec in self:
rec.qty_refunded = sum(
rec.refund_line_ids.filtered(
lambda i: i.move_id.state in ("open", "paid")
lambda i: i.move_id.state in ("posted")
).mapped("quantity")
)
@@ -122,12 +120,16 @@ class RmaOrderLine(models.Model):
if not res.get("domain"):
res["domain"] = {}
domain = [
"&",
"&",
("rma_line_id", "=", False),
("exclude_from_invoice_tab", "=", False),
"|",
("move_id.partner_id", "=", self.partner_id.id),
("move_id.partner_id", "child_of", self.partner_id.id),
]
if self.product_id:
domain.append(("product_id", "=", self.product_id.id))
# if self.product_id:
# domain.insert(2, ("product_id", "=", self.product_id.id))
res["domain"]["account_move_line_id"] = domain
return res
@@ -247,27 +249,29 @@ class RmaOrderLine(models.Model):
return {}
def action_view_invoice(self):
action = self.env.ref("account.action_invoice_tree")
result = action.read()[0]
res = self.env.ref("account.view_move_form", False)
result["views"] = [(res and res.id or False, "form")]
result["view_id"] = res and res.id or False
result["res_id"] = self.account_move_line_id.move_id.id
return result
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)
return {
"domain": [("id", "in", [self.account_move_line_id.move_id.id])],
"name": "Originating Invoice",
"res_model": "account.move",
"type": "ir.actions.act_window",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}
def action_view_refunds(self):
action = self.env.ref("account.action_invoice_tree2")
result = action.read()[0]
move_ids = self.mapped("refund_line_ids.move_id").ids
if move_ids:
# choose the view_mode accordingly
if len(move_ids) > 1:
result["domain"] = [("id", "in", move_ids)]
else:
res = self.env.ref("account.move_supplier_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = move_ids[0]
return result
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)
return {
"domain": [("id", "in", move_ids)],
"name": "Refunds",
"res_model": "account.move",
"type": "ir.actions.act_window",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}
def name_get(self):
res = []