mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[9.0][REW] rma_account: adapt.
This commit is contained in:
@@ -11,7 +11,7 @@ class AccountInvoice(models.Model):
|
|||||||
@api.one
|
@api.one
|
||||||
def _compute_rma_count(self):
|
def _compute_rma_count(self):
|
||||||
for inv in self:
|
for inv in self:
|
||||||
rmas = self.mapped('invoice_line_ids.rma_line_ids.rma_id')
|
rmas = self.mapped('invoice_line_ids.rma_line_ids')
|
||||||
inv.rma_count = len(rmas)
|
inv.rma_count = len(rmas)
|
||||||
|
|
||||||
rma_count = fields.Integer(
|
rma_count = fields.Integer(
|
||||||
@@ -19,28 +19,28 @@ class AccountInvoice(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_rma_supplier(self):
|
def action_view_rma_supplier(self):
|
||||||
action = self.env.ref('rma.action_rma_supplier')
|
action = self.env.ref('rma.action_rma_supplier_lines')
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
|
rma_list = self.mapped('invoice_line_ids.rma_line_ids').ids
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(rma_list) != 1:
|
if len(rma_list) != 1:
|
||||||
result['domain'] = [('id', 'in', rma_list)]
|
result['domain'] = [('id', 'in', rma_list)]
|
||||||
elif len(rma_list) == 1:
|
elif len(rma_list) == 1:
|
||||||
res = self.env.ref('rma.view_rma_supplier_form', False)
|
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result['views'] = [(res and res.id or False, 'form')]
|
||||||
result['res_id'] = rma_list[0]
|
result['res_id'] = rma_list[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_rma_customer(self):
|
def action_view_rma_customer(self):
|
||||||
action = self.env.ref('rma.action_rma_customer')
|
action = self.env.ref('rma.action_rma_customer_lines')
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
|
rma_list = self.mapped('invoice_line_ids.rma_line_ids').ids
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(rma_list) != 1:
|
if len(rma_list) != 1:
|
||||||
result['domain'] = [('id', 'in', rma_list)]
|
result['domain'] = [('id', 'in', rma_list)]
|
||||||
elif len(rma_list) == 1:
|
elif len(rma_list) == 1:
|
||||||
res = self.env.ref('rma.view_rma_form', False)
|
res = self.env.ref('rma.view_rma_line_form', False)
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result['views'] = [(res and res.id or False, 'form')]
|
||||||
result['res_id'] = rma_list[0]
|
result['res_id'] = rma_list[0]
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ class RmaOrder(models.Model):
|
|||||||
invoices = rec.mapped('rma_line_ids.invoice_id')
|
invoices = rec.mapped('rma_line_ids.invoice_id')
|
||||||
rec.invoice_count = len(invoices)
|
rec.invoice_count = len(invoices)
|
||||||
|
|
||||||
add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice',
|
add_invoice_id = fields.Many2one(
|
||||||
|
comodel_name='account.invoice', string='Add Invoice',
|
||||||
ondelete='set null', readonly=True,
|
ondelete='set null', readonly=True,
|
||||||
states={'draft': [('readonly', False)]})
|
)
|
||||||
invoice_refund_count = fields.Integer(
|
invoice_refund_count = fields.Integer(
|
||||||
compute=_compute_invoice_refund_count, string='# of Refunds')
|
compute=_compute_invoice_refund_count, string='# of Refunds')
|
||||||
invoice_count = fields.Integer(
|
invoice_count = fields.Integer(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
# © 2017 Eficent Business and IT Consulting Services 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 openerp import _, api, fields, models
|
from openerp import _, api, fields, models
|
||||||
|
from openerp.exceptions import ValidationError, UserError
|
||||||
from openerp.addons import decimal_precision as dp
|
from openerp.addons import decimal_precision as dp
|
||||||
from openerp.exceptions import UserError
|
|
||||||
|
|
||||||
|
|
||||||
class RmaOrderLine(models.Model):
|
class RmaOrderLine(models.Model):
|
||||||
@@ -44,14 +44,18 @@ class RmaOrderLine(models.Model):
|
|||||||
invoice_address_id = fields.Many2one(
|
invoice_address_id = fields.Many2one(
|
||||||
'res.partner', string='Partner invoice address',
|
'res.partner', string='Partner invoice address',
|
||||||
default=_default_invoice_address,
|
default=_default_invoice_address,
|
||||||
help="Invoice address for current rma order.")
|
readonly=True, states={'draft': [('readonly', False)]},
|
||||||
|
help="Invoice address for current rma order.",
|
||||||
|
)
|
||||||
refund_count = fields.Integer(
|
refund_count = fields.Integer(
|
||||||
compute=_compute_refund_count, string='# of Refunds', default=0)
|
compute=_compute_refund_count, string='# of Refunds', default=0)
|
||||||
invoice_line_id = fields.Many2one('account.invoice.line',
|
invoice_line_id = fields.Many2one(
|
||||||
string='Invoice Line',
|
comodel_name='account.invoice.line',
|
||||||
|
string='Originating Invoice Line',
|
||||||
ondelete='restrict',
|
ondelete='restrict',
|
||||||
index=True)
|
index=True,
|
||||||
|
readonly=True, states={'draft': [('readonly', False)]},
|
||||||
|
)
|
||||||
refund_line_ids = fields.One2many(comodel_name='account.invoice.line',
|
refund_line_ids = fields.One2many(comodel_name='account.invoice.line',
|
||||||
inverse_name='rma_line_id',
|
inverse_name='rma_line_id',
|
||||||
string='Refund Lines',
|
string='Refund Lines',
|
||||||
@@ -62,7 +66,9 @@ class RmaOrderLine(models.Model):
|
|||||||
refund_policy = fields.Selection([
|
refund_policy = fields.Selection([
|
||||||
('no', 'No refund'), ('ordered', 'Based on Ordered Quantities'),
|
('no', 'No refund'), ('ordered', 'Based on Ordered Quantities'),
|
||||||
('received', 'Based on Received Quantities')], string="Refund Policy",
|
('received', 'Based on Received Quantities')], string="Refund Policy",
|
||||||
required=True, default='no')
|
required=True, default='no',
|
||||||
|
readonly=True, states={'draft': [('readonly', False)]},
|
||||||
|
)
|
||||||
qty_to_refund = fields.Float(
|
qty_to_refund = fields.Float(
|
||||||
string='Qty To Refund', copy=False,
|
string='Qty To Refund', copy=False,
|
||||||
digits=dp.get_precision('Product Unit of Measure'), readonly=True,
|
digits=dp.get_precision('Product Unit of Measure'), readonly=True,
|
||||||
@@ -72,6 +78,75 @@ class RmaOrderLine(models.Model):
|
|||||||
digits=dp.get_precision('Product Unit of Measure'),
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
readonly=True, compute=_compute_qty_refunded, store=True)
|
readonly=True, compute=_compute_qty_refunded, store=True)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _prepare_rma_line_from_inv_line(self, line):
|
||||||
|
self.ensure_one()
|
||||||
|
if not self.type:
|
||||||
|
self.type = self._get_default_type()
|
||||||
|
if self.type == 'customer':
|
||||||
|
operation = line.product_id.rma_customer_operation_id or \
|
||||||
|
line.product_id.categ_id.rma_customer_operation_id
|
||||||
|
else:
|
||||||
|
operation = line.product_id.rma_supplier_operation_id or \
|
||||||
|
line.product_id.categ_id.rma_supplier_operation_id
|
||||||
|
if not operation:
|
||||||
|
operation = self.env['rma.operation'].search(
|
||||||
|
[('type', '=', self.type)], limit=1)
|
||||||
|
if not operation:
|
||||||
|
raise ValidationError("Please define an operation first")
|
||||||
|
|
||||||
|
if not operation.in_route_id or not operation.out_route_id:
|
||||||
|
route = self.env['stock.location.route'].search(
|
||||||
|
[('rma_selectable', '=', True)], limit=1)
|
||||||
|
if not route:
|
||||||
|
raise ValidationError("Please define an rma route")
|
||||||
|
|
||||||
|
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||||
|
warehouse = self.env['stock.warehouse'].search(
|
||||||
|
[('company_id', '=', self.company_id.id),
|
||||||
|
('lot_rma_id', '!=', False)], limit=1)
|
||||||
|
if not warehouse:
|
||||||
|
raise ValidationError("Please define a warehouse with a"
|
||||||
|
" default rma location")
|
||||||
|
data = {
|
||||||
|
'product_id': line.product_id.id,
|
||||||
|
'origin': line.invoice_id.number,
|
||||||
|
'uom_id': line.uom_id.id,
|
||||||
|
'operation_id': operation.id,
|
||||||
|
'product_qty': line.quantity,
|
||||||
|
'price_unit': line.invoice_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,
|
||||||
|
'receipt_policy': operation.receipt_policy,
|
||||||
|
'refund_policy': operation.refund_policy,
|
||||||
|
'delivery_policy': operation.delivery_policy,
|
||||||
|
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
||||||
|
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
||||||
|
'in_route_id': operation.in_route_id.id or route.id,
|
||||||
|
'out_route_id': operation.out_route_id.id or route.id,
|
||||||
|
'location_id': (operation.location_id.id or
|
||||||
|
operation.in_warehouse_id.lot_rma_id.id or
|
||||||
|
warehouse.lot_rma_id.id),
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|
||||||
|
@api.onchange('invoice_line_id')
|
||||||
|
def _onchange_invoice_line_id(self):
|
||||||
|
if not self.invoice_line_id:
|
||||||
|
return
|
||||||
|
data = self._prepare_rma_line_from_inv_line(
|
||||||
|
self.invoice_line_id)
|
||||||
|
self.update(data)
|
||||||
|
self._remove_other_data_origin('invoice_line_id')
|
||||||
|
|
||||||
|
@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
|
||||||
|
return res
|
||||||
|
|
||||||
@api.onchange('operation_id')
|
@api.onchange('operation_id')
|
||||||
def _onchange_operation_id(self):
|
def _onchange_operation_id(self):
|
||||||
result = super(RmaOrderLine, self)._onchange_operation_id()
|
result = super(RmaOrderLine, self)._onchange_operation_id()
|
||||||
@@ -80,14 +155,6 @@ class RmaOrderLine(models.Model):
|
|||||||
self.refund_policy = self.operation_id.refund_policy
|
self.refund_policy = self.operation_id.refund_policy
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.onchange('invoice_line_id')
|
|
||||||
def _onchange_invoice_line_id(self):
|
|
||||||
result = {}
|
|
||||||
if not self.invoice_line_id:
|
|
||||||
return result
|
|
||||||
self.origin = self.invoice_id.number
|
|
||||||
return result
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.constrains('invoice_line_id')
|
@api.constrains('invoice_line_id')
|
||||||
def _check_duplicated_lines(self):
|
def _check_duplicated_lines(self):
|
||||||
|
|||||||
@@ -15,9 +15,13 @@
|
|||||||
string="Refunds"/>
|
string="Refunds"/>
|
||||||
</button>
|
</button>
|
||||||
</button>
|
</button>
|
||||||
|
<group name="main_info" position="inside">
|
||||||
|
<field name="invoice_line_id"
|
||||||
|
options="{'no_create': True}"
|
||||||
|
domain="[('invoice_id.partner_id', '=', partner_id)]"/>
|
||||||
|
</group>
|
||||||
<field name="operation_id" position="after">
|
<field name="operation_id" position="after">
|
||||||
<field name="refund_policy"/>
|
<field name="refund_policy"/>
|
||||||
<field name="invoice_line_id" invisible="True"/>
|
|
||||||
</field>
|
</field>
|
||||||
<page name="stock" position="after">
|
<page name="stock" position="after">
|
||||||
<page name="refunds" string="Refunds">
|
<page name="refunds" string="Refunds">
|
||||||
@@ -51,9 +55,13 @@
|
|||||||
string="Refunds"/>
|
string="Refunds"/>
|
||||||
</button>
|
</button>
|
||||||
</button>
|
</button>
|
||||||
|
<group name="main_info" position="inside">
|
||||||
|
<field name="invoice_line_id"
|
||||||
|
options="{'no_create': True}"
|
||||||
|
domain="[('invoice_id.partner_id', '=', partner_id)]"/>
|
||||||
|
</group>
|
||||||
<field name="operation_id" position="after">
|
<field name="operation_id" position="after">
|
||||||
<field name="refund_policy"/>
|
<field name="refund_policy"/>
|
||||||
<field name="invoice_line_id" invisible="True"/>
|
|
||||||
</field>
|
</field>
|
||||||
<page name="stock" position="after">
|
<page name="stock" position="after">
|
||||||
<page name="refunds" string="Refunds">
|
<page name="refunds" string="Refunds">
|
||||||
|
|||||||
@@ -109,12 +109,11 @@
|
|||||||
<field name="model">rma.order</field>
|
<field name="model">rma.order</field>
|
||||||
<field name="inherit_id" ref="rma.view_rma_form"/>
|
<field name="inherit_id" ref="rma.view_rma_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<button name="action_rma_done" position="after">
|
<xpath expr="//header" position="inside">
|
||||||
<button name="%(action_rma_add_invoice)d"
|
<button name="%(action_rma_add_invoice)d"
|
||||||
string="Add From Invoice"
|
string="Add From Invoice"
|
||||||
type="action"
|
type="action"/>
|
||||||
states="draft,to_approve"/>
|
</xpath>
|
||||||
</button>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
@@ -123,12 +122,11 @@
|
|||||||
<field name="model">rma.order</field>
|
<field name="model">rma.order</field>
|
||||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<button name="action_rma_done" position="after">
|
<xpath expr="//header" position="inside">
|
||||||
<button name="%(action_rma_add_invoice_supplier)d"
|
<button name="%(action_rma_add_invoice_supplier)d"
|
||||||
string="Add From Invoice"
|
string="Add From Invoice"
|
||||||
type="action"
|
type="action"/>
|
||||||
states="draft,to_approve"/>
|
</xpath>
|
||||||
</button>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,11 @@
|
|||||||
<field name="model">rma.order.line</field>
|
<field name="model">rma.order.line</field>
|
||||||
<field name="inherit_id" ref="rma.view_rma_line_form"/>
|
<field name="inherit_id" ref="rma.view_rma_line_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<header position="inside">
|
<xpath expr="//header" position="inside">
|
||||||
<button name="%(action_rma_refund)d" states="approved"
|
<button name="%(action_rma_refund)d" states="approved"
|
||||||
string="Create Refund" class="oe_highlight"
|
string="Create Refund" class="oe_highlight"
|
||||||
type="action"/>
|
type="action"/>
|
||||||
</header>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
@@ -63,11 +63,11 @@
|
|||||||
<field name="model">rma.order.line</field>
|
<field name="model">rma.order.line</field>
|
||||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_button_form"/>
|
<field name="inherit_id" ref="rma.view_rma_line_supplier_button_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<header position="inside">
|
<xpath expr="//header" position="inside">
|
||||||
<button name="%(action_rma_refund)d" states="approved"
|
<button name="%(action_rma_refund)d" states="approved"
|
||||||
string="Create Refund" class="oe_highlight"
|
string="Create Refund" class="oe_highlight"
|
||||||
type="action"/>
|
type="action"/>
|
||||||
</header>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user