mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] default operation in product and product_categ for customer and supplier
[IMP]Separate menus for customer and supplier operations * Add active field to rma operation * Added tests * Fix travis * Fix create supplier rma from customer rma
This commit is contained in:
@@ -9,21 +9,21 @@ class RmaOrder(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_refund_count(self):
|
||||
self.ensure_one()
|
||||
invoice_list = []
|
||||
for line in self.rma_line_ids:
|
||||
for refund in line.refund_line_ids:
|
||||
invoice_list.append(refund.invoice_id.id)
|
||||
self.invoice_refund_count = len(list(set(invoice_list)))
|
||||
for rec in self:
|
||||
invoice_list = []
|
||||
for line in rec.rma_line_ids:
|
||||
for refund in line.refund_line_ids:
|
||||
invoice_list.append(refund.invoice_id.id)
|
||||
rec.invoice_refund_count = len(list(set(invoice_list)))
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_count(self):
|
||||
self.ensure_one()
|
||||
invoice_list = []
|
||||
for line in self.rma_line_ids:
|
||||
if line.invoice_line_id and line.invoice_line_id.id:
|
||||
invoice_list.append(line.invoice_line_id.invoice_id.id)
|
||||
self.invoice_count = len(list(set(invoice_list)))
|
||||
for rec in self:
|
||||
invoice_list = []
|
||||
for line in rec.rma_line_ids:
|
||||
if line.invoice_line_id and line.invoice_line_id.id:
|
||||
invoice_list.append(line.invoice_line_id.invoice_id.id)
|
||||
rec.invoice_count = len(list(set(invoice_list)))
|
||||
|
||||
add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice',
|
||||
ondelete='set null', readonly=True,
|
||||
@@ -37,11 +37,12 @@ class RmaOrder(models.Model):
|
||||
copy=False)
|
||||
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
operation = line.product_id.rma_operation_id and \
|
||||
line.product_id.rma_operation_id.id or False
|
||||
if not operation:
|
||||
operation = line.product_id.categ_id.rma_operation_id and \
|
||||
line.product_id.categ_id.rma_operation_id.id or False
|
||||
if self.type == 'customer':
|
||||
operation = self.product_id.rma_customer_operation_id or \
|
||||
self.product_id.categ_id.rma_customer_operation_id
|
||||
else:
|
||||
operation = self.product_id.rma_supplier_operation_id or \
|
||||
self.product_id.categ_id.rma_supplier_operation_id
|
||||
data = {
|
||||
'invoice_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<field name="invoice_address_id"
|
||||
groups='rma.group_rma_delivery_invoice_address'/>
|
||||
</field>
|
||||
<group name="deliver">
|
||||
<group name="deliver" position="after">
|
||||
<group name="refund">
|
||||
<field name="qty_to_refund"/>
|
||||
<field name="qty_refunded"/>
|
||||
@@ -64,7 +64,7 @@
|
||||
<field name="invoice_address_id"
|
||||
groups='rma.group_rma_delivery_invoice_address'/>
|
||||
</field>
|
||||
<group name="deliver">
|
||||
<group name="supplier_rma" position="after">
|
||||
<group name="refund">
|
||||
<field name="qty_to_refund"/>
|
||||
<field name="qty_refunded"/>
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
import time
|
||||
from openerp import _, api, fields, models
|
||||
from openerp import api, fields, models
|
||||
from openerp.exceptions import ValidationError
|
||||
|
||||
|
||||
@@ -20,11 +19,9 @@ class RmaAddinvoice(models.TransientModel):
|
||||
if not rma_id:
|
||||
return res
|
||||
assert active_model == 'rma.order', 'Bad context propagation'
|
||||
|
||||
rma = rma_obj.browse(rma_id)
|
||||
res['rma_id'] = rma.id
|
||||
res['partner_id'] = rma.partner_id.id
|
||||
res['invoice_id'] = False
|
||||
res['invoice_line_ids'] = False
|
||||
return res
|
||||
|
||||
@@ -32,8 +29,6 @@ class RmaAddinvoice(models.TransientModel):
|
||||
ondelete='cascade')
|
||||
partner_id = fields.Many2one(comodel_name='res.partner', string='Partner',
|
||||
readonly=True)
|
||||
invoice_id = fields.Many2one(comodel_name='account.invoice',
|
||||
string='Invoice')
|
||||
invoice_line_ids = fields.Many2many('account.invoice.line',
|
||||
'rma_add_invoice_add_line_rel',
|
||||
'invoice_line_id',
|
||||
@@ -41,8 +36,12 @@ class RmaAddinvoice(models.TransientModel):
|
||||
string='Invoice Lines')
|
||||
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
operation = line.product_id.rma_operation_id or \
|
||||
line.product_id.categ_id.rma_operation_id
|
||||
if self.env.context.get('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
|
||||
data = {
|
||||
'invoice_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
@@ -52,8 +51,8 @@ class RmaAddinvoice(models.TransientModel):
|
||||
'product_qty': line.quantity,
|
||||
'price_unit': line.invoice_id.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False),
|
||||
'delivery_address_id': self.invoice_id.partner_id.id,
|
||||
'invoice_address_id': self.invoice_id.partner_id.id,
|
||||
'delivery_address_id': line.invoice_id.partner_id.id,
|
||||
'invoice_address_id': line.invoice_id.partner_id.id,
|
||||
'rma_id': self.rma_id.id
|
||||
}
|
||||
if not operation:
|
||||
@@ -66,16 +65,26 @@ class RmaAddinvoice(models.TransientModel):
|
||||
[('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.rma_id.company_id.id),
|
||||
('lot_rma_id', '!=', False)], limit=1)
|
||||
if not warehouse:
|
||||
raise ValidationError("Please define a warehouse with a"
|
||||
" default rma location")
|
||||
data.update(
|
||||
{'in_route_id': operation.in_route_id.id,
|
||||
'out_route_id': operation.out_route_id.id,
|
||||
'in_warehouse_id': operation.in_warehouse_id.id,
|
||||
'out_warehouse_id': operation.out_warehouse_id.id,
|
||||
'receipt_policy': operation.receipt_policy,
|
||||
'location_id': operation.location_id.id,
|
||||
{'receipt_policy': operation.receipt_policy,
|
||||
'operation_id': operation.id,
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_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
|
||||
|
||||
@@ -83,8 +92,10 @@ class RmaAddinvoice(models.TransientModel):
|
||||
def _get_rma_data(self):
|
||||
data = {
|
||||
'date_rma': fields.Datetime.now(),
|
||||
'delivery_address_id': self.invoice_id.partner_id.id,
|
||||
'invoice_address_id': self.invoice_id.partner_id.id
|
||||
'delivery_address_id':
|
||||
self.invoice_line_ids[0].invoice_id.partner_id.id,
|
||||
'invoice_address_id':
|
||||
self.invoice_line_ids[0].invoice_id.partner_id.id
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
@@ -11,17 +11,51 @@
|
||||
domain="[('customer','=',True)]"
|
||||
string="Customer"/>
|
||||
</group>
|
||||
<separator string="Select Invoice from customer"/>
|
||||
<separator string="Select Invoices lines to add"/>
|
||||
<field name="invoice_line_ids"
|
||||
domain="[('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.type', '=', 'out_invoice')]">
|
||||
<tree string="Invoice Lines">
|
||||
<field name="invoice_id"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="account.group_account_user"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uom_id" groups="product.group_uom"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="sale.group_discount_per_so_line"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<footer>
|
||||
<button
|
||||
string="Confirm"
|
||||
name="add_lines" type="object"
|
||||
class="oe_highlight"/>
|
||||
or
|
||||
<button name="action_cancel"
|
||||
string="Cancel" class="oe_link" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_invoice_supplier" model="ir.ui.view">
|
||||
<field name="name">rma.add.invoice.supplier</field>
|
||||
<field name="model">rma_add_invoice</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Invoice from supplier">
|
||||
<group>
|
||||
<field name="invoice_id"
|
||||
domain="[('type','=','out_invoice'),'|',('commercial_partner_id','=',partner_id),
|
||||
('partner_id','=',partner_id), (('state','not in',['draft','cancel']))]"
|
||||
context="{'form_view_ref':'account.invoice_form','partner_id': partner_id}"/>
|
||||
<field name="partner_id"
|
||||
domain="[('supplier','=',True)]"
|
||||
string="Supplier"/>
|
||||
</group>
|
||||
<separator string="Select Invoices lines to add"/>
|
||||
<field name="invoice_line_ids"
|
||||
domain="[('invoice_id', '=', invoice_id)]">
|
||||
domain="[('invoice_id.partner_id', '=', partner_id),
|
||||
('invoice_id.type', '=', 'in_invoice')]">
|
||||
<tree string="Invoice Lines">
|
||||
<field name="invoice_id"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="account.group_account_user"/>
|
||||
<field name="quantity"/>
|
||||
@@ -54,9 +88,20 @@
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_invoice"/>
|
||||
<field name="groups_id" eval="[(4, ref('rma.group_rma_customer_user')), (4, ref('rma.group_rma_customer_user'))]"/>
|
||||
<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">
|
||||
<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="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_invoice_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">
|
||||
<field name="name">rma.order.line.form</field>
|
||||
@@ -78,7 +123,7 @@
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_rma_done" position="after">
|
||||
<button name="%(action_rma_add_invoice)d"
|
||||
<button name="%(action_rma_add_invoice_supplier)d"
|
||||
string="Add From Invoice"
|
||||
type="action"
|
||||
states="draft,to_approve"/>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import openerp.addons.decimal_precision as dp
|
||||
from openerp import api, models
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
from openerp import models, fields, exceptions, api, _
|
||||
from openerp import _, api, exceptions, fields, models
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user