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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user