[ENH]rma_sale traceability

This commit is contained in:
ahenriquez
2020-01-23 11:37:38 +01:00
parent 9086e69f1f
commit c3afb525c0
6 changed files with 90 additions and 11 deletions

View File

@@ -10,7 +10,7 @@
<button type="object" <button type="object"
name="action_open_partner_rma" name="action_open_partner_rma"
class="oe_stat_button" class="oe_stat_button"
icon="fa-eject" icon="fa-dropbox"
context="{'res_partner_search_mode': 'customer'}" context="{'res_partner_search_mode': 'customer'}"
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user"> groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
<field name="rma_line_count" widget="statinfo" <field name="rma_line_count" widget="statinfo"

View File

@@ -1,6 +1,7 @@
# Copyright 2020 ForgeFlow S.L. # Copyright 2020 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import sale_order_line from . import sale_order_line
from . import sale_order
from . import rma_order_line from . import rma_order_line
from . import rma_order from . import rma_order
from . import rma_operation from . import rma_operation

View File

@@ -0,0 +1,36 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
rma_line_ids = fields.One2many(
comodel_name="rma.order.line", compute="_compute_rma_line"
)
rma_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
def _compute_rma_count(self):
for so in self:
rmas = self.mapped("rma_line_ids")
so.rma_count = len(rmas)
def _compute_rma_line(self):
for so in self:
so.rma_line_ids = so.mapped("order_line.rma_line_id")
def action_view_rma(self):
action = self.env.ref("rma.action_rma_customer_lines")
result = action.read()[0]
rma_ids = self.mapped("rma_line_ids").ids
if rma_ids:
# choose the view_mode accordingly
if len(rma_ids) > 1:
result["domain"] = [("id", "in", rma_ids)]
else:
res = self.env.ref("rma.view_rma_line_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = rma_ids[0]
return result

View File

@@ -14,4 +14,27 @@
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="view_order_form_inherit_sale_rma" model="ir.ui.view">
<field name="name">sale.order.form.sale.rma</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//button[@name='action_view_invoice']" position="before">
<button type="object"
name="action_view_rma"
class="oe_stat_button"
icon="fa-dropbox"
attrs="{'invisible': [('rma_count', '=', 0)]}"
groups="rma.group_rma_customer_user">
<field name="rma_count" widget="statinfo" string="RMA"/>
</button>
</xpath>
</data>
</field>
</record>
</odoo> </odoo>

View File

@@ -18,7 +18,9 @@ class RmaLineMakeSaleOrder(models.TransientModel):
comodel_name="rma.order.line.make.sale.order.item", comodel_name="rma.order.line.make.sale.order.item",
inverse_name="wiz_id", inverse_name="wiz_id",
string="Items", string="Items",
readonly=False,
) )
sale_order_id = fields.Many2one( sale_order_id = fields.Many2one(
comodel_name="sale.order", comodel_name="sale.order",
string="Sales Order", string="Sales Order",
@@ -67,16 +69,17 @@ class RmaLineMakeSaleOrder(models.TransientModel):
return res return res
@api.model @api.model
def _prepare_sale_order(self, out_warehouse, company, item): def _prepare_sale_order(self, line):
if not self.partner_id: if not self.partner_id:
raise exceptions.Warning(_("Enter a customer.")) raise exceptions.Warning(_("Enter a customer."))
customer = self.partner_id customer = self.partner_id
data = { data = {
"origin": item.line_id.name, "origin": line.name,
"partner_id": customer.id, "partner_id": customer.id,
"warehouse_id": out_warehouse.id, "warehouse_id": line.out_warehouse_id.id,
"company_id": company.id, "company_id": line.company_id.id,
} }
return data return data
@api.model @api.model
@@ -108,10 +111,9 @@ class RmaLineMakeSaleOrder(models.TransientModel):
if self.sale_order_id: if self.sale_order_id:
sale = self.sale_order_id sale = self.sale_order_id
if not sale: if not sale:
po_data = self._prepare_sale_order( po_data = self._prepare_sale_order(line)
line.out_warehouse_id, line.company_id, item
)
sale = sale_obj.create(po_data) sale = sale_obj.create(po_data)
sale.name = sale.name + " - " + line.name
so_line_data = self._prepare_sale_order_line(sale, item) so_line_data = self._prepare_sale_order_line(sale, item)
so_line_obj.create(so_line_data) so_line_obj.create(so_line_data)
@@ -130,7 +132,9 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
wiz_id = fields.Many2one( wiz_id = fields.Many2one(
comodel_name="rma.order.line.make.sale.order", string="Wizard" comodel_name="rma.order.line.make.sale.order", string="Wizard"
) )
line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line") line_id = fields.Many2one(
comodel_name="rma.order.line", string="RMA Line", compute="_compute_line_id"
)
rma_id = fields.Many2one( rma_id = fields.Many2one(
comodel_name="rma.order", related="line_id.rma_id", readonly=False comodel_name="rma.order", related="line_id.rma_id", readonly=False
) )
@@ -142,3 +146,17 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
comodel_name="stock.warehouse", string="Outbound Warehouse" comodel_name="stock.warehouse", string="Outbound Warehouse"
) )
free_of_charge = fields.Boolean(string="Free of Charge") free_of_charge = fields.Boolean(string="Free of Charge")
def _compute_line_id(self):
rma_line_obj = self.env["rma.order.line"]
for rec in self:
if not self.env.context["active_ids"]:
return
rma_line_ids = self.env.context["active_ids"] or []
lines = rma_line_obj.browse(rma_line_ids)
rec.line_id = lines[0]
@api.onchange("product_id")
def onchange_product_id(self):
if self.product_id:
self.name = self.product_id.name

View File

@@ -26,9 +26,10 @@
<newline/> <newline/>
<group> <group>
<field name="item_ids" nolabel="1" colspan="2"> <field name="item_ids" nolabel="1" colspan="2">
<tree string="Details" editable="bottom" create="false"> <tree string="Details" editable="bottom">
<field name="wiz_id" invisible="True"/>
<field name="line_id" <field name="line_id"
options="{'no_open': true}"/> invisible="True"/>
<field name="product_id"/> <field name="product_id"/>
<field name="name"/> <field name="name"/>
<field name="product_qty"/> <field name="product_qty"/>