mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX]rma_account refund creation
This commit is contained in:
@@ -10,9 +10,9 @@
|
|||||||
"author": "ForgeFlow",
|
"author": "ForgeFlow",
|
||||||
"website": "https://github.com/ForgeFlow/stock-rma",
|
"website": "https://github.com/ForgeFlow/stock-rma",
|
||||||
"depends": ["stock_account", "rma"],
|
"depends": ["stock_account", "rma"],
|
||||||
"demo": ["data/rma_operation.xml"],
|
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
|
"data/rma_operation.xml",
|
||||||
"views/rma_order_view.xml",
|
"views/rma_order_view.xml",
|
||||||
"views/rma_operation_view.xml",
|
"views/rma_operation_view.xml",
|
||||||
"views/rma_order_line_view.xml",
|
"views/rma_order_line_view.xml",
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class RmaOrderLine(models.Model):
|
|||||||
qty_to_refund = fields.Float(
|
qty_to_refund = fields.Float(
|
||||||
string="Qty To Refund",
|
string="Qty To Refund",
|
||||||
copy=False,
|
copy=False,
|
||||||
digits=dp.get_precision("Product Unit of Measure"),
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
compute="_compute_qty_to_refund",
|
compute="_compute_qty_to_refund",
|
||||||
store=True,
|
store=True,
|
||||||
@@ -109,7 +109,7 @@ class RmaOrderLine(models.Model):
|
|||||||
qty_refunded = fields.Float(
|
qty_refunded = fields.Float(
|
||||||
string="Qty Refunded",
|
string="Qty Refunded",
|
||||||
copy=False,
|
copy=False,
|
||||||
digits=dp.get_precision("Product Unit of Measure"),
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
compute="_compute_qty_refunded",
|
compute="_compute_qty_refunded",
|
||||||
store=True,
|
store=True,
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ class RmaRefund(models.TransientModel):
|
|||||||
first = self.item_ids[0]
|
first = self.item_ids[0]
|
||||||
values = self._prepare_refund(wizard, first.line_id)
|
values = self._prepare_refund(wizard, first.line_id)
|
||||||
new_refund = self.env["account.move"].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.move.line"].create(refund_line_values)
|
|
||||||
return new_refund
|
return new_refund
|
||||||
|
|
||||||
def invoice_refund(self):
|
def invoice_refund(self):
|
||||||
@@ -96,9 +93,9 @@ class RmaRefund(models.TransientModel):
|
|||||||
raise ValidationError(_("RMA %s is not approved") % line.name)
|
raise ValidationError(_("RMA %s is not approved") % line.name)
|
||||||
new_invoice = self.compute_refund()
|
new_invoice = self.compute_refund()
|
||||||
action = (
|
action = (
|
||||||
"action_invoice_tree1"
|
"action_move_out_refund_type"
|
||||||
if (new_invoice.type in ["out_refund", "out_invoice"])
|
if (new_invoice.type in ["out_refund", "out_invoice"])
|
||||||
else "action_invoice_in_refund"
|
else "action_move_in_refund_type"
|
||||||
)
|
)
|
||||||
result = self.env.ref("account.%s" % action).read()[0]
|
result = self.env.ref("account.%s" % action).read()[0]
|
||||||
form_view = self.env.ref("account.move_supplier_form", False)
|
form_view = self.env.ref("account.move_supplier_form", False)
|
||||||
@@ -107,7 +104,7 @@ class RmaRefund(models.TransientModel):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def prepare_refund_line(self, item, refund):
|
def prepare_refund_line(self, item):
|
||||||
accounts = item.product_id.product_tmpl_id._get_product_accounts()
|
accounts = item.product_id.product_tmpl_id._get_product_accounts()
|
||||||
if item.line_id.type == "customer":
|
if item.line_id.type == "customer":
|
||||||
account = accounts["stock_output"]
|
account = accounts["stock_output"]
|
||||||
@@ -115,6 +112,7 @@ class RmaRefund(models.TransientModel):
|
|||||||
account = accounts["stock_input"]
|
account = accounts["stock_input"]
|
||||||
if not account:
|
if not account:
|
||||||
raise ValidationError(_("Accounts are not configured for this product."))
|
raise ValidationError(_("Accounts are not configured for this product."))
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"name": item.line_id.name or item.rma_id.name,
|
"name": item.line_id.name or item.rma_id.name,
|
||||||
"account_id": account.id,
|
"account_id": account.id,
|
||||||
@@ -125,7 +123,6 @@ class RmaRefund(models.TransientModel):
|
|||||||
"product_id": item.product_id.id,
|
"product_id": item.product_id.id,
|
||||||
"rma_line_id": item.line_id.id,
|
"rma_line_id": item.line_id.id,
|
||||||
"quantity": item.qty_to_refund,
|
"quantity": item.qty_to_refund,
|
||||||
"move_id": refund.id,
|
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@@ -142,8 +139,10 @@ class RmaRefund(models.TransientModel):
|
|||||||
)
|
)
|
||||||
values = {
|
values = {
|
||||||
"name": rma_line.rma_id.name or rma_line.name,
|
"name": rma_line.rma_id.name or rma_line.name,
|
||||||
|
"invoice_payment_ref": rma_line.rma_id.name or rma_line.name,
|
||||||
"invoice_origin": rma_line.rma_id.name or rma_line.name,
|
"invoice_origin": rma_line.rma_id.name or rma_line.name,
|
||||||
"ref": False,
|
"ref": False,
|
||||||
|
"type": "in_refund" if rma_line.type == "supplier" else "out_refund",
|
||||||
"journal_id": journal.id,
|
"journal_id": journal.id,
|
||||||
"currency_id": rma_line.partner_id.company_id.currency_id.id,
|
"currency_id": rma_line.partner_id.company_id.currency_id.id,
|
||||||
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
|
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
|
||||||
@@ -152,6 +151,9 @@ class RmaRefund(models.TransientModel):
|
|||||||
"date": wizard.date,
|
"date": wizard.date,
|
||||||
"invoice_date": wizard.date_invoice,
|
"invoice_date": wizard.date_invoice,
|
||||||
"partner_id": rma_line.invoice_address_id.id or rma_line.partner_id.id,
|
"partner_id": rma_line.invoice_address_id.id or rma_line.partner_id.id,
|
||||||
|
"invoice_line_ids": [
|
||||||
|
(0, None, self.prepare_refund_line(item)) for item in self.item_ids
|
||||||
|
],
|
||||||
}
|
}
|
||||||
if self.env.registry.models.get("crm.team", False):
|
if self.env.registry.models.get("crm.team", False):
|
||||||
team_ids = self.env["crm.team"].search(
|
team_ids = self.env["crm.team"].search(
|
||||||
@@ -196,13 +198,13 @@ class RmaRefundItem(models.TransientModel):
|
|||||||
rma_id = fields.Many2one(
|
rma_id = fields.Many2one(
|
||||||
"rma.order", related="line_id.rma_id", string="RMA", readonly=True
|
"rma.order", related="line_id.rma_id", string="RMA", readonly=True
|
||||||
)
|
)
|
||||||
product_id = fields.Many2one("product.product", string="Product")
|
product_id = fields.Many2one("product.product", string="Product (Technical)")
|
||||||
product = fields.Many2one("product.product", string="Product", readonly=True)
|
product = fields.Many2one("product.product", string="Product", readonly=True)
|
||||||
name = fields.Char(string="Description", required=True)
|
name = fields.Char(string="Description", required=True)
|
||||||
product_qty = fields.Float(
|
product_qty = fields.Float(
|
||||||
string="Quantity Ordered",
|
string="Quantity Ordered",
|
||||||
copy=False,
|
copy=False,
|
||||||
digits=dp.get_precision("Product Unit of Measure"),
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
invoice_address_id = fields.Many2one(
|
invoice_address_id = fields.Many2one(
|
||||||
|
|||||||
Reference in New Issue
Block a user