mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[MIG]rma_account to v13
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
|
||||
{
|
||||
"name": "RMA Account",
|
||||
"version": "12.0.1.0.0",
|
||||
"version": "13.0.1.0.0",
|
||||
"license": "LGPL-3",
|
||||
"category": "RMA",
|
||||
"summary": "Integrates RMA with Invoice Processing",
|
||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||
"author": "ForgeFlow",
|
||||
"website": "https://github.com/ForgeFlow/stock-rma",
|
||||
"depends": ["stock_account", "rma"],
|
||||
"demo": ["data/rma_operation.xml"],
|
||||
@@ -16,9 +16,9 @@
|
||||
"views/rma_order_view.xml",
|
||||
"views/rma_operation_view.xml",
|
||||
"views/rma_order_line_view.xml",
|
||||
"views/invoice_view.xml",
|
||||
"views/account_move_view.xml",
|
||||
"views/rma_account_menu.xml",
|
||||
"wizards/rma_add_invoice.xml",
|
||||
"wizards/rma_add_account_move.xml",
|
||||
"wizards/rma_refund.xml",
|
||||
],
|
||||
"installable": True,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo noupdate="0">
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="rma.rma_operation_customer_replace" model="rma.operation">
|
||||
<field name="refund_policy">no</field>
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
from . import rma_order
|
||||
from . import rma_order_line
|
||||
from . import rma_operation
|
||||
from . import invoice
|
||||
from . import account_move
|
||||
|
||||
@@ -5,13 +5,13 @@ from odoo import api, fields, models
|
||||
from odoo.tools.float_utils import float_compare
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = "account.invoice"
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
@api.depends("invoice_line_ids.rma_line_ids")
|
||||
@api.depends("line_ids.rma_line_ids")
|
||||
def _compute_rma_count(self):
|
||||
for inv in self:
|
||||
rmas = self.mapped("invoice_line_ids.rma_line_ids")
|
||||
rmas = self.mapped("line_ids.rma_line_ids")
|
||||
inv.rma_count = len(rmas)
|
||||
|
||||
def _prepare_invoice_line_from_rma_line(self, line):
|
||||
@@ -19,18 +19,17 @@ class AccountInvoice(models.Model):
|
||||
if float_compare(qty, 0.0, precision_rounding=line.uom_id.rounding) <= 0:
|
||||
qty = 0.0
|
||||
# Todo fill taxes from somewhere
|
||||
invoice_line = self.env["account.invoice.line"]
|
||||
invoice_line = self.env["account.move.line"]
|
||||
data = {
|
||||
"purchase_line_id": line.id,
|
||||
"name": line.name + ": " + line.name,
|
||||
"origin": line.origin,
|
||||
"uom_id": line.uom_id.id,
|
||||
"product_uom_id": line.uom_id.id,
|
||||
"product_id": line.product_id.id,
|
||||
"account_id": invoice_line.with_context(
|
||||
{"journal_id": self.journal_id.id, "type": "in_invoice"}
|
||||
)._default_account(),
|
||||
"price_unit": line.company_id.currency_id.with_context(
|
||||
date=self.date_invoice
|
||||
date=self.date
|
||||
).compute(line.price_unit, self.currency_id, round=False),
|
||||
"quantity": qty,
|
||||
"discount": 0.0,
|
||||
@@ -45,12 +44,12 @@ class AccountInvoice(models.Model):
|
||||
if not self.partner_id:
|
||||
self.partner_id = self.add_rma_line_id.partner_id.id
|
||||
|
||||
new_line = self.env["account.invoice.line"]
|
||||
if self.add_rma_line_id not in (self.invoice_line_ids.mapped("rma_line_id")):
|
||||
new_line = self.env["account.move.line"]
|
||||
if self.add_rma_line_id not in (self.line_ids.mapped("rma_line_id")):
|
||||
data = self._prepare_invoice_line_from_rma_line(self.add_rma_line_id)
|
||||
new_line = new_line.new(data)
|
||||
new_line._set_additional_fields(self)
|
||||
self.invoice_line_ids += new_line
|
||||
self.line_ids += new_line
|
||||
self.add_rma_line_id = False
|
||||
return {}
|
||||
|
||||
@@ -63,11 +62,10 @@ class AccountInvoice(models.Model):
|
||||
help="Create a refund in based on an existing rma_line",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def action_view_rma_supplier(self):
|
||||
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||
result = action.read()[0]
|
||||
rma_ids = self.mapped("invoice_line_ids.rma_line_ids").ids
|
||||
rma_ids = self.mapped("line_ids.rma_line_ids").ids
|
||||
if rma_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_ids) > 1:
|
||||
@@ -78,11 +76,10 @@ class AccountInvoice(models.Model):
|
||||
result["res_id"] = rma_ids[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_rma_customer(self):
|
||||
action = self.env.ref("rma.action_rma_customer_lines")
|
||||
result = action.read()[0]
|
||||
rma_ids = self.mapped("invoice_line_ids.rma_line_ids").ids
|
||||
rma_ids = self.mapped("line_ids.rma_line_ids").ids
|
||||
if rma_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_ids) > 1:
|
||||
@@ -94,8 +91,8 @@ class AccountInvoice(models.Model):
|
||||
return result
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = "account.invoice.line"
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator="ilike", limit=100):
|
||||
@@ -104,7 +101,7 @@ class AccountInvoiceLine(models.Model):
|
||||
will make impossible to get the desired result."""
|
||||
if not args:
|
||||
args = []
|
||||
lines = self.search([("invoice_id.number", operator, name)] + args, limit=limit)
|
||||
lines = self.search([("move_id.name", operator, name)] + args, limit=limit)
|
||||
res = lines.name_get()
|
||||
if limit:
|
||||
limit_rest = limit - len(lines)
|
||||
@@ -113,50 +110,48 @@ class AccountInvoiceLine(models.Model):
|
||||
limit_rest = limit
|
||||
if limit_rest or not limit:
|
||||
args += [("id", "not in", lines.ids)]
|
||||
res += super(AccountInvoiceLine, self).name_search(
|
||||
res += super(AccountMoveLine, self).name_search(
|
||||
name, args=args, operator=operator, limit=limit_rest
|
||||
)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get("rma"):
|
||||
for inv in self:
|
||||
if inv.invoice_id.reference:
|
||||
if inv.move_id.ref:
|
||||
res.append(
|
||||
(
|
||||
inv.id,
|
||||
"INV:%s | REF:%s | ORIG:%s | PART:%s | QTY:%s"
|
||||
% (
|
||||
inv.invoice_id.number or "",
|
||||
inv.origin or "",
|
||||
inv.invoice_id.reference or "",
|
||||
inv.move_id.name or "",
|
||||
inv.move_id.invoice_origin or "",
|
||||
inv.move_id.ref or "",
|
||||
inv.product_id.name,
|
||||
inv.quantity,
|
||||
),
|
||||
)
|
||||
)
|
||||
elif inv.invoice_id.number:
|
||||
elif inv.move_id.name:
|
||||
res.append(
|
||||
(
|
||||
inv.id,
|
||||
"INV:%s | ORIG:%s | PART:%s | QTY:%s"
|
||||
% (
|
||||
inv.invoice_id.number or "",
|
||||
inv.origin or "",
|
||||
inv.move_id.name or "",
|
||||
inv.move_id.invoice_origin or "",
|
||||
inv.product_id.name,
|
||||
inv.quantity,
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
res.append(super(AccountInvoiceLine, inv).name_get()[0])
|
||||
res.append(super(AccountMoveLine, inv).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(AccountInvoiceLine, self).name_get()
|
||||
return super(AccountMoveLine, self).name_get()
|
||||
|
||||
@api.multi
|
||||
def _compute_rma_count(self):
|
||||
for invl in self:
|
||||
rma_lines = invl.mapped("rma_line_ids")
|
||||
@@ -165,7 +160,7 @@ class AccountInvoiceLine(models.Model):
|
||||
rma_line_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
|
||||
rma_line_ids = fields.One2many(
|
||||
comodel_name="rma.order.line",
|
||||
inverse_name="invoice_line_id",
|
||||
inverse_name="account_move_line_id",
|
||||
string="RMA",
|
||||
readonly=True,
|
||||
help="This will contain the RMA lines for the invoice line",
|
||||
@@ -7,20 +7,18 @@ from odoo import api, fields, models
|
||||
class RmaOrder(models.Model):
|
||||
_inherit = "rma.order"
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_refund_count(self):
|
||||
for rec in self:
|
||||
invoices = rec.mapped("rma_line_ids.refund_line_ids.invoice_id")
|
||||
invoices = rec.mapped("rma_line_ids.refund_line_ids.move_id")
|
||||
rec.invoice_refund_count = len(invoices)
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_count(self):
|
||||
for rec in self:
|
||||
invoices = rec.mapped("rma_line_ids.invoice_id")
|
||||
invoices = rec.mapped("rma_line_ids.move_id")
|
||||
rec.invoice_count = len(invoices)
|
||||
|
||||
add_invoice_id = fields.Many2one(
|
||||
comodel_name="account.invoice",
|
||||
add_move_id = fields.Many2one(
|
||||
comodel_name="account.move",
|
||||
string="Add Invoice",
|
||||
ondelete="set null",
|
||||
readonly=True,
|
||||
@@ -44,30 +42,30 @@ class RmaOrder(models.Model):
|
||||
or self.rma_line_ids.product_id.categ_id.rma_supplier_operation_id
|
||||
)
|
||||
data = {
|
||||
"invoice_line_id": line.id,
|
||||
"account_move_line_id": line.id,
|
||||
"product_id": line.product_id.id,
|
||||
"name": line.name,
|
||||
"origin": line.invoice_id.number,
|
||||
"uom_id": line.uom_id.id,
|
||||
"origin": line.move_id.name,
|
||||
"uom_id": line.product_uom_id.id,
|
||||
"operation_id": operation,
|
||||
"product_qty": line.quantity,
|
||||
"price_unit": line.invoice_id.currency_id.compute(
|
||||
"price_unit": line.move_id.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False
|
||||
),
|
||||
"rma_id": self.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@api.onchange("add_invoice_id")
|
||||
@api.onchange("add_move_id")
|
||||
def on_change_invoice(self):
|
||||
if not self.add_invoice_id:
|
||||
if not self.add_move_id:
|
||||
return {}
|
||||
if not self.partner_id:
|
||||
self.partner_id = self.add_invoice_id.partner_id.id
|
||||
self.partner_id = self.add_move_id.partner_id.id
|
||||
new_lines = self.env["rma.order.line"]
|
||||
for line in self.add_invoice_id.invoice_line_ids:
|
||||
for line in self.add_move_id.line_ids:
|
||||
# Load a PO line only once
|
||||
if line in self.rma_line_ids.mapped("invoice_line_id"):
|
||||
if line in self.rma_line_ids.mapped("account_move_line_id"):
|
||||
continue
|
||||
data = self._prepare_rma_line_from_inv_line(line)
|
||||
new_line = new_lines.new(data)
|
||||
@@ -75,9 +73,9 @@ class RmaOrder(models.Model):
|
||||
|
||||
self.rma_line_ids += new_lines
|
||||
self.date_rma = fields.Datetime.now()
|
||||
self.delivery_address_id = self.add_invoice_id.partner_id.id
|
||||
self.invoice_address_id = self.add_invoice_id.partner_id.id
|
||||
self.add_invoice_id = False
|
||||
self.delivery_address_id = self.add_move_id.partner_id.id
|
||||
self.invoice_address_id = self.add_move_id.partner_id.id
|
||||
self.add_move_id = False
|
||||
return {}
|
||||
|
||||
@api.model
|
||||
@@ -92,36 +90,34 @@ class RmaOrder(models.Model):
|
||||
res["invoice_address_id"] = partner.id
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def action_view_invoice_refund(self):
|
||||
action = self.env.ref("account.action_invoice_tree2")
|
||||
result = action.read()[0]
|
||||
invoice_ids = self.mapped("rma_line_ids.refund_line_ids.invoice_id").ids
|
||||
if invoice_ids:
|
||||
move_ids = self.mapped("rma_line_ids.refund_line_ids.move_id").ids
|
||||
if move_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) > 1:
|
||||
result["domain"] = [("id", "in", invoice_ids)]
|
||||
if len(move_ids) > 1:
|
||||
result["domain"] = [("id", "in", move_ids)]
|
||||
else:
|
||||
res = self.env.ref("account.invoice_supplier_form", False)
|
||||
res = self.env.ref("account.move_supplier_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = invoice_ids[0]
|
||||
result["res_id"] = move_ids[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_invoice(self):
|
||||
if self.type == "supplier":
|
||||
action = self.env.ref("account.action_invoice_tree2")
|
||||
res = self.env.ref("account.invoice_supplier_form", False)
|
||||
res = self.env.ref("account.move_supplier_form", False)
|
||||
else:
|
||||
action = self.env.ref("account.action_invoice_tree")
|
||||
res = self.env.ref("account.invoice_form", False)
|
||||
res = self.env.ref("account.view_move_form", False)
|
||||
result = action.read()[0]
|
||||
invoice_ids = self.mapped("rma_line_ids.invoice_id").ids
|
||||
if invoice_ids:
|
||||
move_ids = self.mapped("rma_line_ids.move_id").ids
|
||||
if move_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) > 1:
|
||||
result["domain"] = [("id", "in", invoice_ids)]
|
||||
if len(move_ids) > 1:
|
||||
result["domain"] = [("id", "in", move_ids)]
|
||||
else:
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = invoice_ids[0]
|
||||
result["res_id"] = move_ids[0]
|
||||
return result
|
||||
|
||||
@@ -17,21 +17,20 @@ class RmaOrderLine(models.Model):
|
||||
return self.env["res.partner"].browse(partner_id)
|
||||
return self.env["res.partner"]
|
||||
|
||||
@api.multi
|
||||
@api.depends(
|
||||
"refund_line_ids", "refund_line_ids.invoice_id.state", "refund_policy", "type"
|
||||
"refund_line_ids", "refund_line_ids.move_id.state", "refund_policy", "type"
|
||||
)
|
||||
def _compute_qty_refunded(self):
|
||||
for rec in self:
|
||||
rec.qty_refunded = sum(
|
||||
rec.refund_line_ids.filtered(
|
||||
lambda i: i.invoice_id.state in ("open", "paid")
|
||||
lambda i: i.move_id.state in ("open", "paid")
|
||||
).mapped("quantity")
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
"refund_line_ids",
|
||||
"refund_line_ids.invoice_id.state",
|
||||
"refund_line_ids.move_id.state",
|
||||
"refund_policy",
|
||||
"move_ids",
|
||||
"move_ids.state",
|
||||
@@ -48,10 +47,9 @@ class RmaOrderLine(models.Model):
|
||||
qty = res.qty_delivered - res.qty_refunded
|
||||
res.qty_to_refund = qty
|
||||
|
||||
@api.multi
|
||||
def _compute_refund_count(self):
|
||||
for rec in self:
|
||||
rec.refund_count = len(rec.refund_line_ids.mapped("invoice_id"))
|
||||
rec.refund_count = len(rec.refund_line_ids.mapped("move_id"))
|
||||
|
||||
invoice_address_id = fields.Many2one(
|
||||
"res.partner",
|
||||
@@ -64,8 +62,8 @@ class RmaOrderLine(models.Model):
|
||||
refund_count = fields.Integer(
|
||||
compute="_compute_refund_count", string="# of Refunds", default=0
|
||||
)
|
||||
invoice_line_id = fields.Many2one(
|
||||
comodel_name="account.invoice.line",
|
||||
account_move_line_id = fields.Many2one(
|
||||
comodel_name="account.move.line",
|
||||
string="Originating Invoice Line",
|
||||
ondelete="restrict",
|
||||
index=True,
|
||||
@@ -73,17 +71,17 @@ class RmaOrderLine(models.Model):
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
refund_line_ids = fields.One2many(
|
||||
comodel_name="account.invoice.line",
|
||||
comodel_name="account.move.line",
|
||||
inverse_name="rma_line_id",
|
||||
string="Refund Lines",
|
||||
copy=False,
|
||||
index=True,
|
||||
readonly=True,
|
||||
)
|
||||
invoice_id = fields.Many2one(
|
||||
"account.invoice",
|
||||
move_id = fields.Many2one(
|
||||
"account.move",
|
||||
string="Source",
|
||||
related="invoice_line_id.invoice_id",
|
||||
related="account_move_line_id.move_id",
|
||||
index=True,
|
||||
readonly=True,
|
||||
)
|
||||
@@ -125,15 +123,14 @@ class RmaOrderLine(models.Model):
|
||||
res["domain"] = {}
|
||||
domain = [
|
||||
"|",
|
||||
("invoice_id.partner_id", "=", self.partner_id.id),
|
||||
("invoice_id.partner_id", "child_of", self.partner_id.id),
|
||||
("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))
|
||||
res["domain"]["invoice_line_id"] = domain
|
||||
res["domain"]["account_move_line_id"] = domain
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
self.ensure_one()
|
||||
if not self.type:
|
||||
@@ -173,15 +170,15 @@ class RmaOrderLine(models.Model):
|
||||
)
|
||||
data = {
|
||||
"product_id": line.product_id.id,
|
||||
"origin": line.invoice_id.number,
|
||||
"uom_id": line.uom_id.id,
|
||||
"origin": line.move_id.name,
|
||||
"uom_id": line.product_uom_id.id,
|
||||
"operation_id": operation.id,
|
||||
"product_qty": line.quantity,
|
||||
"price_unit": line.invoice_id.currency_id.compute(
|
||||
"price_unit": line.move_id.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False
|
||||
),
|
||||
"delivery_address_id": line.invoice_id.partner_id.id,
|
||||
"invoice_address_id": line.invoice_id.partner_id.id,
|
||||
"delivery_address_id": line.move_id.partner_id.id,
|
||||
"invoice_address_id": line.move_id.partner_id.id,
|
||||
"receipt_policy": operation.receipt_policy,
|
||||
"refund_policy": operation.refund_policy,
|
||||
"delivery_policy": operation.delivery_policy,
|
||||
@@ -198,21 +195,20 @@ class RmaOrderLine(models.Model):
|
||||
}
|
||||
return data
|
||||
|
||||
@api.onchange("invoice_line_id")
|
||||
def _onchange_invoice_line_id(self):
|
||||
if not self.invoice_line_id:
|
||||
@api.onchange("account_move_line_id")
|
||||
def _onchange_account_move_line_id(self):
|
||||
if not self.account_move_line_id:
|
||||
return
|
||||
data = self._prepare_rma_line_from_inv_line(self.invoice_line_id)
|
||||
data = self._prepare_rma_line_from_inv_line(self.account_move_line_id)
|
||||
self.update(data)
|
||||
self._remove_other_data_origin("invoice_line_id")
|
||||
self._remove_other_data_origin("account_move_line_id")
|
||||
|
||||
@api.multi
|
||||
@api.constrains("invoice_line_id", "partner_id")
|
||||
@api.constrains("account_move_line_id", "partner_id")
|
||||
def _check_invoice_partner(self):
|
||||
for rec in self:
|
||||
if (
|
||||
rec.invoice_line_id
|
||||
and rec.invoice_line_id.invoice_id.partner_id != rec.partner_id
|
||||
rec.account_move_line_id
|
||||
and rec.account_move_line_id.move_id.partner_id != rec.partner_id
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
@@ -221,11 +217,10 @@ class RmaOrderLine(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _remove_other_data_origin(self, exception):
|
||||
res = super(RmaOrderLine, self)._remove_other_data_origin(exception)
|
||||
if not exception == "invoice_line_id":
|
||||
self.invoice_line_id = False
|
||||
if not exception == "account_move_line_id":
|
||||
self.account_move_line_id = False
|
||||
return res
|
||||
|
||||
@api.onchange("operation_id")
|
||||
@@ -235,49 +230,45 @@ class RmaOrderLine(models.Model):
|
||||
self.refund_policy = self.operation_id.refund_policy or "no"
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@api.constrains("invoice_line_id")
|
||||
@api.constrains("account_move_line_id")
|
||||
def _check_duplicated_lines(self):
|
||||
for line in self:
|
||||
matching_inv_lines = self.env["account.invoice.line"].search(
|
||||
[("id", "=", line.invoice_line_id.id)]
|
||||
matching_inv_lines = self.env["account.move.line"].search(
|
||||
[("id", "=", line.account_move_line_id.id)]
|
||||
)
|
||||
if len(matching_inv_lines) > 1:
|
||||
raise UserError(
|
||||
_(
|
||||
"There's an rma for the invoice line %s "
|
||||
"and invoice %s"
|
||||
% (line.invoice_line_id, line.invoice_line_id.invoice_id)
|
||||
% (line.account_move_line_id, line.account_move_line_id.move_id)
|
||||
)
|
||||
)
|
||||
return {}
|
||||
|
||||
@api.multi
|
||||
def action_view_invoice(self):
|
||||
action = self.env.ref("account.action_invoice_tree")
|
||||
result = action.read()[0]
|
||||
res = self.env.ref("account.invoice_form", False)
|
||||
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.invoice_line_id.invoice_id.id
|
||||
result["res_id"] = self.account_move_line_id.move_id.id
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_refunds(self):
|
||||
action = self.env.ref("account.action_invoice_tree2")
|
||||
result = action.read()[0]
|
||||
invoice_ids = self.mapped("refund_line_ids.invoice_id").ids
|
||||
if invoice_ids:
|
||||
move_ids = self.mapped("refund_line_ids.move_id").ids
|
||||
if move_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) > 1:
|
||||
result["domain"] = [("id", "in", invoice_ids)]
|
||||
if len(move_ids) > 1:
|
||||
result["domain"] = [("id", "in", move_ids)]
|
||||
else:
|
||||
res = self.env.ref("account.invoice_supplier_form", False)
|
||||
res = self.env.ref("account.move_supplier_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = invoice_ids[0]
|
||||
result["res_id"] = move_ids[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get("rma"):
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_account_invoice_customer_user,access_account_invoice,account.model_account_invoice,rma.group_rma_customer_user,1,0,0,0
|
||||
access_account_invoice_supplier_user,access_account_invoice,account.model_account_invoice,rma.group_rma_supplier_user,1,0,0,0
|
||||
access_account_move_customer_user,access_account_move,account.model_account_move,rma.group_rma_customer_user,1,0,0,0
|
||||
access_account_move_supplier_user,access_account_move,account.model_account_move,rma.group_rma_supplier_user,1,0,0,0
|
||||
access_account_move_line_customer_user,access_account_move_line,account.model_account_move_line,rma.group_rma_customer_user,1,0,0,0
|
||||
access_account_move_line_supplier_user,access_account_move_line,account.model_account_move_line,rma.group_rma_supplier_user,1,0,0,0
|
||||
|
||||
|
@@ -15,8 +15,8 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
|
||||
cls.rma_refund_wiz = cls.env["rma.refund"]
|
||||
cls.acc_obj = cls.env["account.account"]
|
||||
cls.inv_obj = cls.env["account.invoice"]
|
||||
cls.invl_obj = cls.env["account.invoice.line"]
|
||||
cls.inv_obj = cls.env["account.move"]
|
||||
cls.invl_obj = cls.env["account.move.line"]
|
||||
cls.product_obj = cls.env["product.product"]
|
||||
cls.partner_obj = cls.env["res.partner"]
|
||||
|
||||
@@ -89,7 +89,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"product_id": cls.product_1.id,
|
||||
"quantity": 12.0,
|
||||
"price_unit": 100.0,
|
||||
"invoice_id": cls.inv_customer.id,
|
||||
"move_id": cls.inv_customer.id,
|
||||
"uom_id": cls.product_1.uom_id.id,
|
||||
"account_id": customer_account,
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"product_id": cls.product_2.id,
|
||||
"quantity": 15.0,
|
||||
"price_unit": 150.0,
|
||||
"invoice_id": cls.inv_customer.id,
|
||||
"move_id": cls.inv_customer.id,
|
||||
"uom_id": cls.product_2.uom_id.id,
|
||||
"account_id": customer_account,
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"product_id": cls.product_3.id,
|
||||
"quantity": 17.0,
|
||||
"price_unit": 250.0,
|
||||
"invoice_id": cls.inv_supplier.id,
|
||||
"move_id": cls.inv_supplier.id,
|
||||
"uom_id": cls.product_3.uom_id.id,
|
||||
"account_id": supplier_account,
|
||||
}
|
||||
@@ -133,7 +133,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"product_id": cls.product_4.id,
|
||||
"quantity": 9.0,
|
||||
"price_unit": 300.0,
|
||||
"invoice_id": cls.inv_supplier.id,
|
||||
"move_id": cls.inv_supplier.id,
|
||||
"uom_id": cls.product_4.uom_id.id,
|
||||
"account_id": supplier_account,
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"active_ids": self.rma_group_customer.id,
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create({"invoice_line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]})
|
||||
).create({"line_ids": [(6, 0, self.inv_customer.line_ids.ids)]})
|
||||
add_inv.add_lines()
|
||||
self.assertEqual(len(self.rma_group_customer.rma_line_ids), 2)
|
||||
for t in self.rma_group_supplier.rma_line_ids.mapped("type"):
|
||||
@@ -169,7 +169,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
"active_ids": self.rma_group_supplier.id,
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create({"invoice_line_ids": [(6, 0, self.inv_supplier.invoice_line_ids.ids)]})
|
||||
).create({"line_ids": [(6, 0, self.inv_supplier.line_ids.ids)]})
|
||||
add_inv.add_lines()
|
||||
self.assertEqual(len(self.rma_group_supplier.rma_line_ids), 2)
|
||||
for t in self.rma_group_supplier.rma_line_ids.mapped("type"):
|
||||
@@ -206,7 +206,7 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
{"customer": True, "active_ids": rma.ids, "active_model": "rma.order.line"}
|
||||
).create({"description": "Test refund"})
|
||||
make_refund.invoice_refund()
|
||||
rma.refund_line_ids.invoice_id.action_invoice_open()
|
||||
rma.refund_line_ids.move_id.action_invoice_open()
|
||||
rma._compute_refund_count()
|
||||
self.assertEqual(rma.refund_count, 1)
|
||||
self.assertEqual(rma.qty_to_refund, 0.0)
|
||||
@@ -217,10 +217,10 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
rma = self.rma_line_obj.new(
|
||||
{
|
||||
"partner_id": self.inv_customer.partner_id.id,
|
||||
"invoice_line_id": self.inv_line_1.id,
|
||||
"account_move_line_id": self.inv_line_1.id,
|
||||
}
|
||||
)
|
||||
self.assertFalse(rma.product_id)
|
||||
rma._onchange_invoice_line_id()
|
||||
rma._onchange_account_move_line_id()
|
||||
self.assertEqual(rma.product_id, self.product_1)
|
||||
self.assertEqual(rma.product_qty, 12.0)
|
||||
|
||||
69
rma_account/views/account_move_view.xml
Normal file
69
rma_account/views/account_move_view.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="name">account.move.form</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="before">
|
||||
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
<button type="object" name="action_view_rma_customer"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_count" widget="statinfo"
|
||||
string="RMA"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_invoice_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.invoice.line.form</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit_id" ref="account.view_move_line_form"/>
|
||||
<field eval="16" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="name" position="after">
|
||||
<field name="rma_line_count" invisible="1"/>
|
||||
<field name="rma_line_id"
|
||||
string="RMA line originated"/>
|
||||
<notebook attrs="{'invisible': [('rma_line_count', '=', 0)]}">
|
||||
<page string="RMA Lines">
|
||||
<field name="rma_line_ids"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_invoice_customer_rma_form" model="ir.ui.view">
|
||||
<field name="name">account.move.customer.rma</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="invoice_vendor_bill_id" position="after">
|
||||
<field name="add_rma_line_id"
|
||||
context="{'rma': True}"
|
||||
domain="[('type', '=', 'customer'),
|
||||
('partner_id', '=', partner_id)]"
|
||||
attrs="{'readonly': [('state','not in',['draft'])],
|
||||
'invisible': ['|', ('state', '=', 'paid'),
|
||||
('type', '=', 'in_invoice')]}" class="oe_edit_only"
|
||||
options="{'no_create': True}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_invoice_line" model="ir.actions.act_window">
|
||||
<field name="name">Invoice Line</field>
|
||||
<field name="res_model">account.move.line</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="account.view_move_line_form"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1,105 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.form</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="number" position="before">
|
||||
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
<button type="object" name="action_view_rma_customer"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_count" widget="statinfo"
|
||||
string="RMA"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_supplier_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.supplier.form</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="number" position="before">
|
||||
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
<button type="object" name="action_view_rma_supplier"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_count" widget="statinfo"
|
||||
string="RMA"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_invoice_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.invoice.line.form</field>
|
||||
<field name="model">account.invoice.line</field>
|
||||
<field name="inherit_id" ref="account.view_invoice_line_form"/>
|
||||
<field eval="16" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="name" position="after">
|
||||
<field name="rma_line_count" invisible="1"/>
|
||||
<field name="rma_line_id"
|
||||
string="RMA line originated"/>
|
||||
<notebook attrs="{'invisible': [('rma_line_count', '=', 0)]}">
|
||||
<page string="RMA Lines">
|
||||
<field name="rma_line_ids"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_invoice_supplier_rma_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.supplier.rma</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="reference" position="after">
|
||||
<field name="add_rma_line_id"
|
||||
context="{'rma': True}"
|
||||
domain="[('type', '=', 'supplier'),
|
||||
('partner_id', '=', partner_id)]"
|
||||
attrs="{'readonly': [('state','not in',['draft'])],
|
||||
'invisible': ['|', ('state', '=', 'paid'),
|
||||
('type', '=', 'out_invoice')]}" class="oe_edit_only"
|
||||
options="{'no_create': True}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_invoice_customer_rma_form" model="ir.ui.view">
|
||||
<field name="name">account.invoice.customer.rma</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_term_id" position="after">
|
||||
<field name="add_rma_line_id"
|
||||
context="{'rma': True}"
|
||||
domain="[('type', '=', 'customer'),
|
||||
('partner_id', '=', partner_id)]"
|
||||
attrs="{'readonly': [('state','not in',['draft'])],
|
||||
'invisible': ['|', ('state', '=', 'paid'),
|
||||
('type', '=', 'in_invoice')]}" class="oe_edit_only"
|
||||
options="{'no_create': True}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_invoice_line" model="ir.actions.act_window">
|
||||
<field name="name">Invoice Line</field>
|
||||
<field name="res_model">account.invoice.line</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="account.view_invoice_line_form"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -8,7 +8,6 @@
|
||||
<field name="res_model">rma.order.line</field>
|
||||
<field name="domain">[('type','=', 'customer')]</field>
|
||||
<field name="context">{"search_default_to_refund":1}</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
@@ -17,11 +16,32 @@
|
||||
<field name="res_model">rma.order.line</field>
|
||||
<field name="domain">[('type','=', 'supplier')]</field>
|
||||
<field name="context">{"search_default_to_refund":1, "supplier":1}</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="rma.view_rma_line_supplier_tree"/>
|
||||
</record>
|
||||
|
||||
<!-- Accountants menu RMA -->
|
||||
<menuitem id="menu_rma_account"
|
||||
name="Accounting"
|
||||
groups="account.group_account_user"
|
||||
sequence="32"
|
||||
parent="rma.menu_rma_root"/>
|
||||
|
||||
<menuitem id="menu_rma_customer_refunds"
|
||||
name="Customer RMA to Refund"
|
||||
sequence="20"
|
||||
parent="rma_account.menu_rma_account"
|
||||
groups="rma.group_rma_customer_user"
|
||||
action="action_rma_account_customer_lines"/>
|
||||
|
||||
<menuitem id="menu_rma_line_supplier_refunds"
|
||||
name="Supplier RMA to Refund"
|
||||
sequence="20"
|
||||
parent="rma_account.menu_rma_account"
|
||||
groups="rma.group_rma_customer_user"
|
||||
action="action_rma_supplier_lines"/>
|
||||
|
||||
|
||||
<menuitem id="menu_rma_line_account_customer"
|
||||
name="Customer RMA to Refund"
|
||||
sequence="20"
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_view_out_shipments" position="after">
|
||||
<button type="object" name="action_view_refunds"
|
||||
<button type="object" name="action_view_invoice"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
string="Origin Inv">
|
||||
</button>
|
||||
<button type="object" name="action_view_refunds"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
groups="account.group_account_user">
|
||||
@@ -15,12 +20,12 @@
|
||||
</button>
|
||||
</button>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="invoice_line_id"
|
||||
<field name="account_move_line_id"
|
||||
options="{'no_create': True}"
|
||||
context="{'rma': True}"
|
||||
domain="['|',
|
||||
('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.partner_id', 'child_of', partner_id)]"/>
|
||||
('move_id.partner_id', '=', partner_id),
|
||||
('move_id.partner_id', 'child_of', partner_id)]"/>
|
||||
</group>
|
||||
<field name="operation_id" position="after">
|
||||
<field name="refund_policy"/>
|
||||
@@ -49,6 +54,11 @@
|
||||
<field name="inherit_id" ref="rma.view_rma_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_view_out_shipments" position="after">
|
||||
<button type="object" name="action_view_invoice"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
string="Origin Inv">
|
||||
</button>
|
||||
<button type="object" name="action_view_refunds"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
@@ -58,12 +68,12 @@
|
||||
</button>
|
||||
</button>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="invoice_line_id"
|
||||
<field name="account_move_line_id"
|
||||
options="{'no_create': True}"
|
||||
context="{'rma': True}"
|
||||
domain="['|',
|
||||
('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.partner_id', 'child_of', partner_id)]"/>
|
||||
('move_id.partner_id', '=', partner_id),
|
||||
('move_id.partner_id', 'child_of', partner_id)]"/>
|
||||
</group>
|
||||
<field name="operation_id" position="after">
|
||||
<field name="refund_policy"/>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<!--
|
||||
<xpath expr="//field[@name='rma_line_ids']/tree/field[@name='price_unit']"
|
||||
position="after">
|
||||
<field name="invoice_line_id" invisible="True"/>
|
||||
<field name="account_move_line_id" invisible="True"/>
|
||||
</xpath>
|
||||
-->
|
||||
</field>
|
||||
@@ -56,7 +56,7 @@
|
||||
<!--
|
||||
<xpath expr="//field[@name='rma_line_ids']/tree"
|
||||
position="inside">
|
||||
<field name="invoice_line_id" invisible="True"/>
|
||||
<field name="account_move_line_id" invisible="True"/>
|
||||
</xpath>
|
||||
-->
|
||||
</field>
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import rma_refund
|
||||
from . import rma_add_invoice
|
||||
from . import rma_add_account_move
|
||||
from . import rma_order_line_make_supplier_rma
|
||||
|
||||
@@ -5,8 +5,8 @@ from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaAddInvoice(models.TransientModel):
|
||||
_name = "rma_add_invoice"
|
||||
class RmaAddAccountMove(models.TransientModel):
|
||||
_name = "rma_add_account_move"
|
||||
_description = "Wizard to add rma lines"
|
||||
|
||||
@api.model
|
||||
@@ -21,7 +21,7 @@ class RmaAddInvoice(models.TransientModel):
|
||||
rma = rma_obj.browse(rma_id)
|
||||
res["rma_id"] = rma.id
|
||||
res["partner_id"] = rma.partner_id.id
|
||||
res["invoice_line_ids"] = False
|
||||
res["line_ids"] = False
|
||||
return res
|
||||
|
||||
rma_id = fields.Many2one(
|
||||
@@ -30,11 +30,11 @@ class RmaAddInvoice(models.TransientModel):
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner", string="Partner", readonly=True
|
||||
)
|
||||
invoice_line_ids = fields.Many2many(
|
||||
"account.invoice.line",
|
||||
"rma_add_invoice_add_line_rel",
|
||||
"invoice_line_id",
|
||||
"rma_add_invoice_id",
|
||||
line_ids = fields.Many2many(
|
||||
"account.move.line",
|
||||
"rma_add_account_move_add_line_rel",
|
||||
"account_move_line_id",
|
||||
"rma_add_move_id",
|
||||
string="Invoice Lines",
|
||||
)
|
||||
|
||||
@@ -76,17 +76,17 @@ class RmaAddInvoice(models.TransientModel):
|
||||
)
|
||||
data = {
|
||||
"partner_id": self.partner_id.id,
|
||||
"invoice_line_id": line.id,
|
||||
"account_move_line_id": line.id,
|
||||
"product_id": line.product_id.id,
|
||||
"origin": line.invoice_id.number,
|
||||
"uom_id": line.uom_id.id,
|
||||
"origin": line.move_id.name,
|
||||
"uom_id": line.product_uom_id.id,
|
||||
"operation_id": operation.id,
|
||||
"product_qty": line.quantity,
|
||||
"price_unit": line.invoice_id.currency_id.compute(
|
||||
"price_unit": line.move_id.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False
|
||||
),
|
||||
"delivery_address_id": line.invoice_id.partner_id.id,
|
||||
"invoice_address_id": line.invoice_id.partner_id.id,
|
||||
"delivery_address_id": line.move_id.partner_id.id,
|
||||
"invoice_address_id": line.move_id.partner_id.id,
|
||||
"rma_id": self.rma_id.id,
|
||||
"receipt_policy": operation.receipt_policy,
|
||||
"refund_policy": operation.refund_policy,
|
||||
@@ -112,14 +112,13 @@ class RmaAddInvoice(models.TransientModel):
|
||||
def _get_existing_invoice_lines(self):
|
||||
existing_invoice_lines = []
|
||||
for rma_line in self.rma_id.rma_line_ids:
|
||||
existing_invoice_lines.append(rma_line.invoice_line_id)
|
||||
existing_invoice_lines.append(rma_line.account_move_line_id)
|
||||
return existing_invoice_lines
|
||||
|
||||
@api.multi
|
||||
def add_lines(self):
|
||||
rma_line_obj = self.env["rma.order.line"]
|
||||
existing_invoice_lines = self._get_existing_invoice_lines()
|
||||
for line in self.invoice_line_ids:
|
||||
for line in self.line_ids:
|
||||
# Load a PO line only once
|
||||
if line not in existing_invoice_lines:
|
||||
data = self._prepare_rma_line_from_inv_line(line)
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_add_invoice" model="ir.ui.view">
|
||||
<record id="view_rma_add_account_move" model="ir.ui.view">
|
||||
<field name="name">rma.add.invoice</field>
|
||||
<field name="model">rma_add_invoice</field>
|
||||
<field name="model">rma_add_account_move</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Invoice from customer">
|
||||
<group>
|
||||
@@ -13,15 +13,16 @@
|
||||
string="Customer"/>
|
||||
</group>
|
||||
<separator string="Select Invoices lines to add"/>
|
||||
<field name="invoice_line_ids"
|
||||
domain="[('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.type', '=', 'out_invoice')]">
|
||||
<field name="line_ids"
|
||||
domain="[('move_id.partner_id', '=', partner_id),
|
||||
('move_id.type', '=', 'out_invoice')]">
|
||||
<tree string="Invoice Lines">
|
||||
<field name="invoice_id"/>
|
||||
<field name="move_id"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="account.group_account_user"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uom_id" groups="uom.group_uom"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_uom_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="base.group_no_one"/>
|
||||
<field name="price_subtotal"/>
|
||||
@@ -41,9 +42,9 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_invoice_supplier" model="ir.ui.view">
|
||||
<record id="view_rma_add_account_move_supplier" model="ir.ui.view">
|
||||
<field name="name">rma.add.invoice.supplier</field>
|
||||
<field name="model">rma_add_invoice</field>
|
||||
<field name="model">rma_add_account_move</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Invoice from supplier">
|
||||
<group>
|
||||
@@ -52,15 +53,16 @@
|
||||
string="Supplier"/>
|
||||
</group>
|
||||
<separator string="Select Invoices lines to add"/>
|
||||
<field name="invoice_line_ids"
|
||||
domain="[('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.type', '=', 'in_invoice')]">
|
||||
<field name="line_ids"
|
||||
domain="[('move_id.partner_id', '=', partner_id),
|
||||
('move_id.type', '=', 'in_invoice')]">
|
||||
<tree string="Invoice Lines">
|
||||
<field name="invoice_id"/>
|
||||
<field name="move_id"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="account.group_account_user"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uom_id" groups="uom.group_uom"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_uom_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="base.group_no_one"/>
|
||||
<field name="price_subtotal"/>
|
||||
@@ -80,50 +82,47 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_add_invoice" model="ir.actions.act_window">
|
||||
<record id="action_rma_add_account_move" model="ir.actions.act_window">
|
||||
<field name="name">Add Invoice</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma_add_invoice</field>
|
||||
<field name="src_model">rma.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="res_model">rma_add_account_move</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_invoice"/>
|
||||
<field name="view_id" ref="view_rma_add_account_move"/>
|
||||
<field name="groups_id" eval="[(4, ref('rma.group_rma_customer_user'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_add_invoice_supplier" model="ir.actions.act_window">
|
||||
<record id="action_rma_add_account_move_supplier" model="ir.actions.act_window">
|
||||
<field name="name">Add Invoice</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma_add_invoice</field>
|
||||
<field name="src_model">rma.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="res_model">rma_add_account_move</field>
|
||||
<field name="binding_model_id" ref="rma.model_rma_order_line"/>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_invoice_supplier"/>
|
||||
<field name="view_id" ref="view_rma_add_account_move_supplier"/>
|
||||
<field name="groups_id" eval="[(4, ref('rma.group_rma_supplier_user'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_invoice_form" model="ir.ui.view">
|
||||
<record id="view_rma_add_account_move_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.form - invoice wizard</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header" position="inside">
|
||||
<button name="%(action_rma_add_invoice)d"
|
||||
<button name="%(action_rma_add_account_move)d"
|
||||
string="Add From Invoice"
|
||||
type="action"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_invoice_button_form" model="ir.ui.view">
|
||||
<record id="view_rma_add_account_move_button_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.supplier.form - invoice wizard</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header" position="inside">
|
||||
<button name="%(action_rma_add_invoice_supplier)d"
|
||||
<button name="%(action_rma_add_account_move_supplier)d"
|
||||
string="Add From Invoice"
|
||||
type="action"/>
|
||||
</xpath>
|
||||
@@ -20,6 +20,7 @@ class RmaRefund(models.TransientModel):
|
||||
def _prepare_item(self, line):
|
||||
values = {
|
||||
"product_id": line.product_id.id,
|
||||
"product": line.product_id.id,
|
||||
"name": line.name,
|
||||
"product_qty": line.product_qty,
|
||||
"uom_id": line.uom_id.id,
|
||||
@@ -64,7 +65,9 @@ class RmaRefund(models.TransientModel):
|
||||
date_invoice = fields.Date(
|
||||
string="Refund Date", default=fields.Date.context_today, required=True
|
||||
)
|
||||
date = fields.Date(string="Accounting Date")
|
||||
date = fields.Date(
|
||||
string="Accounting Date", default=fields.Date.context_today, required=True
|
||||
)
|
||||
description = fields.Char(
|
||||
string="Reason", required=True, default=lambda self: self._get_reason()
|
||||
)
|
||||
@@ -72,18 +75,16 @@ class RmaRefund(models.TransientModel):
|
||||
comodel_name="rma.refund.item", inverse_name="wiz_id", string="Items"
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def compute_refund(self):
|
||||
for wizard in self:
|
||||
first = self.item_ids[0]
|
||||
values = self._prepare_refund(wizard, first.line_id)
|
||||
new_refund = self.env["account.invoice"].create(values)
|
||||
new_refund = self.env["account.move"].create(values)
|
||||
for item in self.item_ids:
|
||||
refund_line_values = self.prepare_refund_line(item, new_refund)
|
||||
self.env["account.invoice.line"].create(refund_line_values)
|
||||
self.env["account.move.line"].create(refund_line_values)
|
||||
return new_refund
|
||||
|
||||
@api.multi
|
||||
def invoice_refund(self):
|
||||
rma_line_ids = self.env["rma.order.line"].browse(self.env.context["active_ids"])
|
||||
for line in rma_line_ids:
|
||||
@@ -100,7 +101,7 @@ class RmaRefund(models.TransientModel):
|
||||
else "action_invoice_in_refund"
|
||||
)
|
||||
result = self.env.ref("account.%s" % action).read()[0]
|
||||
form_view = self.env.ref("account.invoice_supplier_form", False)
|
||||
form_view = self.env.ref("account.move_supplier_form", False)
|
||||
result["views"] = [(form_view and form_view.id or False, "form")]
|
||||
result["res_id"] = new_invoice.id
|
||||
return result
|
||||
@@ -116,14 +117,15 @@ class RmaRefund(models.TransientModel):
|
||||
raise ValidationError(_("Accounts are not configured for this product."))
|
||||
values = {
|
||||
"name": item.line_id.name or item.rma_id.name,
|
||||
"origin": item.line_id.name or item.rma_id.name,
|
||||
"account_id": account.id,
|
||||
"debit": item.line_id.price_unit, # todo fix
|
||||
"credit": item.line_id.price_unit,
|
||||
"price_unit": item.line_id.price_unit,
|
||||
"uom_id": item.line_id.uom_id.id,
|
||||
"product_uom_id": item.line_id.uom_id.id,
|
||||
"product_id": item.product_id.id,
|
||||
"rma_line_id": item.line_id.id,
|
||||
"quantity": item.qty_to_refund,
|
||||
"invoice_id": refund.id,
|
||||
"move_id": refund.id,
|
||||
}
|
||||
return values
|
||||
|
||||
@@ -140,17 +142,15 @@ class RmaRefund(models.TransientModel):
|
||||
)
|
||||
values = {
|
||||
"name": rma_line.rma_id.name or rma_line.name,
|
||||
"origin": rma_line.rma_id.name or rma_line.name,
|
||||
"reference": False,
|
||||
# 'account_id': account.id,
|
||||
"invoice_origin": rma_line.rma_id.name or rma_line.name,
|
||||
"ref": False,
|
||||
"journal_id": journal.id,
|
||||
"currency_id": rma_line.partner_id.company_id.currency_id.id,
|
||||
"payment_term_id": False,
|
||||
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
|
||||
"state": "draft",
|
||||
"number": False,
|
||||
"currency_id": rma_line.currency_id.id,
|
||||
"date": wizard.date,
|
||||
"date_invoice": wizard.date_invoice,
|
||||
"invoice_date": wizard.date_invoice,
|
||||
"partner_id": rma_line.invoice_address_id.id or rma_line.partner_id.id,
|
||||
}
|
||||
if self.env.registry.models.get("crm.team", False):
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_invoice"/>
|
||||
<field name="date" groups="base.group_no_one"/>
|
||||
<field name="date"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="item_ids">
|
||||
<tree string="RMA Lines" editable="bottom">
|
||||
<field name="rma_id"/>
|
||||
<field name="rma_id" invisible="1"/>
|
||||
<field name="product_id" invisible="1"/>
|
||||
<field name="product"/>
|
||||
<field name="name"/>
|
||||
@@ -36,9 +36,9 @@
|
||||
<record id="action_rma_refund" model="ir.actions.act_window">
|
||||
<field name="name">Create Refund</field>
|
||||
<field name="res_model">rma.refund</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_rma_refund"/>
|
||||
<field name="binding_model_id" ref="rma.model_rma_order_line"/>
|
||||
<field name="groups_id"
|
||||
eval="[(4, ref('account.group_account_invoice'))]"/>
|
||||
<field name="target">new</field>
|
||||
|
||||
Reference in New Issue
Block a user