Move crm_claim_rma from __unported__

This commit is contained in:
Aristobulo Meneses
2015-07-31 10:07:29 +02:00
parent 1be17a3630
commit a787c6a7a3
22 changed files with 244 additions and 255 deletions

View File

@@ -1,112 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests import common
class test_lp_1282584(common.TransactionCase):
""" Test wizard open the right type of view
The wizard can generate picking.in and picking.out
Let's ensure it open the right view for each picking type
"""
def setUp(self):
super(test_lp_1282584, self).setUp()
cr, uid = self.cr, self.uid
self.WizardMakePicking = self.registry('claim_make_picking.wizard')
ClaimLine = self.registry('claim.line')
Claim = self.registry('crm.claim')
self.product_id = self.ref('product.product_product_4')
self.partner_id = self.ref('base.res_partner_12')
# Create the claim with a claim line
self.claim_id = Claim.create(
cr, uid,
{
'name': 'TEST CLAIM',
'number': 'TEST CLAIM',
'claim_type': 'customer',
'delivery_address_id': self.partner_id,
})
claim = Claim.browse(cr, uid, self.claim_id)
self.warehouse_id = claim.warehouse_id.id
self.claim_line_id = ClaimLine.create(
cr, uid,
{
'name': 'TEST CLAIM LINE',
'claim_origine': 'none',
'product_id': self.product_id,
'claim_id': self.claim_id,
'location_dest_id': claim.warehouse_id.lot_stock_id.id
})
def test_00(self):
"""Test wizard opened view model for a new product return
"""
cr, uid = self.cr, self.uid
wiz_context = {
'active_id': self.claim_id,
'partner_id': self.partner_id,
'warehouse_id': self.warehouse_id,
'picking_type': 'in',
}
wizard_id = self.WizardMakePicking.create(cr, uid, {
}, context=wiz_context)
res = self.WizardMakePicking.action_create_picking(
cr, uid, [wizard_id], context=wiz_context)
self.assertEquals(res.get('res_model'), 'stock.picking.in',
"Wrong model defined")
def test_01(self):
"""Test wizard opened view model for a new delivery
"""
cr, uid = self.cr, self.uid
WizardChangeProductQty = self.registry('stock.change.product.qty')
wiz_context = {'active_id': self.product_id}
wizard_chg_qty_id = WizardChangeProductQty.create(cr, uid, {
'product_id': self.product_id,
'new_quantity': 12})
WizardChangeProductQty.change_product_qty(cr, uid,
[wizard_chg_qty_id],
context=wiz_context)
wiz_context = {
'active_id': self.claim_id,
'partner_id': self.partner_id,
'warehouse_id': self.warehouse_id,
'picking_type': 'out',
}
wizard_id = self.WizardMakePicking.create(cr, uid, {
}, context=wiz_context)
res = self.WizardMakePicking.action_create_picking(
cr, uid, [wizard_id], context=wiz_context)
self.assertEquals(res.get('res_model'), 'stock.picking.out',
"Wrong model defined")

View File

@@ -22,17 +22,17 @@
#
##############################################################################
import calendar
import math
from openerp.osv import fields, orm, osv
from openerp.models import Model, api, _, NewId
from openerp.models import Model, api, _
from openerp.fields import (Char, Date, Float, One2many, Many2one, Selection,
Text)
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
DEFAULT_SERVER_DATETIME_FORMAT)
from openerp import SUPERUSER_ID
from openerp.exceptions import except_orm, Warning, ValidationError
import math
import calendar
from datetime import datetime
from dateutil.relativedelta import relativedelta
class InvoiceNoDate(Exception):
@@ -71,7 +71,6 @@ class ClaimLine(Model):
# Method to calculate total amount of the line : qty*UP
@api.one
def _line_total_amount(self):
res = {}
self.return_value = (self.unit_sale_price *
self.product_returned_quantity)
@@ -260,11 +259,11 @@ class ClaimLine(Model):
values = self._warranty_limit_values(invoice, claim_type, product,
claim_date)
except InvoiceNoDate:
raise osv.except_osv(
raise Warning(
_('Error'), _('Cannot find any date for invoice. '
'Must be a validated invoice.'))
except ProductNoSupplier:
raise osv.except_osv(
raise Warning(
_('Error'), _('The product has no supplier configured.'))
self.write(values)
@@ -308,7 +307,7 @@ class ClaimLine(Model):
# claim_exists = not isinstance(claim.id, NewId)
if not claim and not (company_id and warehouse_id and
claim_type and claim_date):
claim_type and claim_date):
# if we have a claim_id, we get the info from there,
# otherwise we get it from the args (on creation typically)
return False
@@ -361,7 +360,6 @@ class ClaimLine(Model):
return {'warranty_return_partner': False,
'warranty_type': False,
'location_dest_id': False}
return_address = None
sellers = product.seller_ids
if sellers:
seller = sellers[0]
@@ -393,7 +391,8 @@ class ClaimLine(Model):
""" Calculate warranty limit and address """
for claim_line in self:
if not (claim_line.product_id and claim_line.invoice_line_id):
raise Warning(_('Please set product and invoice.'))
raise Warning(
_('Error'), _('Please set product and invoice.'))
claim_line.set_warranty_limit()
claim_line.set_warranty_return_address()
@@ -404,7 +403,6 @@ class CrmClaim(Model):
_inherit = 'crm.claim'
def init(self, cr):
cr.execute("""
UPDATE "crm_claim" SET "number"=id::varchar
WHERE ("number" is NULL)
@@ -418,12 +416,9 @@ class CrmClaim(Model):
return res
def _get_default_warehouse(self):
user = self.env.user
company_id = user.company_id.id
company_id = self.env.user.company_id.id
wh_obj = self.env['stock.warehouse']
wh = wh_obj.search([
('company_id', '=', company_id)
], limit=1)
wh = wh_obj.search([('company_id', '=', company_id)], limit=1)
if not wh:
raise Warning(
_('There is no warehouse for the current user\'s company.'))
@@ -472,22 +467,13 @@ class CrmClaim(Model):
default='customer',
help="Customer: from customer to company.\n "
"Supplier: from company to supplier.")
claim_line_ids = One2many(
'claim.line',
'claim_id',
string='Return lines')
claim_line_ids = One2many('claim.line', 'claim_id', string='Return lines')
planned_revenue = Float(string='Expected revenue')
planned_cost = Float(string='Expected cost')
real_revenue = Float(string='Real revenue')
real_cost = Float(string='Real cost')
invoice_ids = One2many(
'account.invoice',
'claim_id',
string='Refunds')
picking_ids = One2many(
'stock.picking',
'claim_id',
string='RMA')
invoice_ids = One2many('account.invoice', 'claim_id', string='Refunds')
picking_ids = One2many('stock.picking', 'claim_id', string='RMA')
invoice_id = Many2one(
'account.invoice',
string='Invoice',
@@ -503,17 +489,18 @@ class CrmClaim(Model):
default=_get_default_warehouse,
required=True)
_sql_constraints = [
('number_uniq', 'unique(number, company_id)',
'Number/Reference must be unique per Company!'),
]
@api.one
@api.constrains('number')
def _check_unq_number(self):
if self.search([
('company_id', '=', self.company_id.id),
('number', '=', self.number),
('id', '!=', self.id)]):
raise ValidationError(_('Claim number has to be unique!'))
@api.onchange('invoice_id', 'warehouse_id', 'claim_type', 'date')
def _onchange_invoice_warehouse_type_date(self):
context = self.env.context
invoice_obj = self.env['account.invoice']
invoice_line_obj = self.env['account.invoice.line']
product_obj = self.env['product.product']
claim_line_obj = self.env['claim.line']
invoice_lines = self.invoice_id.invoice_line
claim_lines = []
@@ -572,13 +559,9 @@ class CrmClaim(Model):
@api.model
def message_get_reply_to(self):
""" Override to get the reply_to of the parent project. """
# return [claim.section_id.message_get_reply_to()[0]
# if claim.section_id else False
# for claim in self.browse(cr, SUPERUSER_ID, ids,
# context=context)]
return [claim.section_id.message_get_reply_to()[0]
if claim.section_id else False
for claim in self]
for claim in self.sudo()]
@api.model
def message_get_suggested_recipients(self):
@@ -594,7 +577,7 @@ class CrmClaim(Model):
self._message_add_suggested_recipient(
recipients, claim,
email=claim.email_from, reason=_('Customer Email'))
except (osv.except_osv, orm.except_orm):
except except_orm:
# no read access rights -> just ignore suggested recipients
# because this imply modifying followers
pass

View File

@@ -21,8 +21,7 @@
<record model="crm.case.section" id="section_after_sales_service">
<field name="name">After Sales Service</field>
<field name="code">ASV</field>
<field name="parent_id" ref="crm.section_sales_department"/>
<!-- <field name="stage_ids" eval="[(4, ref('crm_claim.stage_claim1')), (4, ref('crm_claim.stage_claim2')), (4, ref('crm_claim.stage_claim3')), (4, ref('crm_claim.stage_claim5'))]"/> -->
<field name="parent_id" ref="sales_team.section_sales_department"/>
</record>
<!--

View File

@@ -221,29 +221,30 @@
</form>
</field>
</group>
<group col="4" colspan="4" attrs="{'invisible': True}" >
<separator string="Action" colspan="4" />
<group col="4" colspan="4" attrs="{'invisible':[('stage_id', 'not in', [%(crm_claim.stage_claim1)d, %(crm_claim.stage_claim5)d])]}">
<separator string="Actions" colspan="4"/>
<button name="%(action_claim_picking_in)d"
string="New Products Return"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
'partner_id': partner_id}"
class="oe_highlight"/>
<button name="%(action_claim_picking_out)d"
string="New Delivery"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
'partner_id': partner_id}"
class="oe_highlight"/>
<button name="%(account.action_account_invoice_refund)d"
type='action' string='New Refund'
icon="gtk-execute"
context="{
'invoice_ids': [invoice_id],
'claim_line_ids': claim_line_ids,
'description': name,
'claim_id': id,
}"/>
'claim_id': id}"
class="oe_highlight"/>
</group>
</page>
<page string="Generated Documents">
@@ -330,40 +331,53 @@
<xpath expr="//sheet[@string='Claims']/group[1]" position="inside">
<div class="oe_right oe_button_box" name="buttons">
<button name="%(act_crm_claim_rma_sale_orders)d" type="action"
string="Quotations and Sales"
string="Sales"
icon="fa-strikethrough"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['supplier','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_invoice_out)d" type="action"
string="Customer Invoices"
string="Invoices"
icon="fa-pencil-square-o"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['supplier','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_refunds_out)d" type="action"
string="Customer Refunds"
string="Refunds"
icon="fa-file-text-o"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['supplier','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_invoice_in)d" type="action"
string="Supplier Invoices"
string="Invoices"
icon="fa-pencil-square-o"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['customer','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_refunds_in)d" type="action"
string="Supplier Refunds"
string="Refunds"
icon="fa-file-text-o"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['customer','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_picking_in)d" type="action"
string="Returned Products"
string="Products"
icon="fa-reply"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['supplier','other'])]}"
context="{'search_default_claim_id': active_id,'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
<button name="%(act_crm_claim_rma_picking_out)d" type="action"
string="Deliveries"
icon="fa-truck"
attrs="{'invisible': ['|',('partner_id','=', False),('claim_type','in', ['supplier','other'])]}"
context="{'search_default_partner_id': [partner_id],'search_default_user_id':False}"
/>
class="oe_inline oe_stat_button"/>
</div>
</xpath>
</field>
@@ -400,15 +414,15 @@
<field name="search_view_id" ref="view_crm_claim_lines_filter"/>
</record>
<!-- substates action -->
<!--<record id="act_crm_claim_substates" model="ir.actions.act_window">-->
<!--<field name="name">Claim line substates</field>-->
<!--<field name="res_model">substate.substate</field>-->
<!--<field name="view_type">form</field>-->
<!--</record>-->
<record id="act_crm_claim_substates" model="ir.actions.act_window">
<field name="name">Claim line substates</field>
<field name="res_model">substate.substate</field>
<field name="view_type">form</field>
</record>
<!-- Menu -->
<menuitem name="Return lines" id="menu_crm_case_claims_claim_lines"
parent="base.menu_aftersale" action="act_crm_case_claim_lines" sequence="2"/>
<!--<menuitem name="Returned line substates" id="menu_crm_case_claims_claim_line_substates"-->
<!--parent="crm_claim.menu_config_claim" action="act_crm_claim_substates" sequence="2"/>-->
<menuitem name="Returned line substates" id="menu_crm_case_claims_claim_line_substates"
parent="crm_claim.menu_config_claim" action="act_crm_claim_substates" sequence="2"/>
</data>
</openerp>

View File

@@ -41,6 +41,7 @@ class StockPicking(Model):
picking = super(StockPicking, self).create(vals)
return picking
# This part concern the case of a wrong picking out. We need to create a new
# stock_move in a picking already open.
# In order to don't have to confirm the stock_move we override the create and

View File

@@ -25,13 +25,13 @@
claim_type: customer
partner_id: base.res_partner_3
invoice_id: account_invoice_claim_refund
state: open
stage_id: crm_claim.stage_claim1
-
I prepare the wizard context.
-
!python {model: account.invoice.refund}: |
claim_lines = self.pool.get('claim.line').search(cr, uid, [('claim_id','=',ref('claim_refund'))])
context.update({'active_model': 'crm_claim', 'active_id': ref('claim_refund'), 'claim_id': ref('claim_refund'), 'claim_line_ids': [[4, claim_lines[0], False], [4, claim_lines[1], False]], 'invoice_ids':[ref('account_invoice_claim_refund')] })
context.update({'active_model': 'crm_claim', 'active_id': ref('claim_refund'), 'claim_id': ref('claim_refund'), 'invoice_ids': [ref('account_invoice_claim_refund')] })
-
I create a refund wizard
-

View File

@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests.common import TransactionCase
class test_lp_1282584(TransactionCase):
""" Test wizard open the right type of view
The wizard can generate picking.in and picking.out
Let's ensure it open the right view for each picking type
"""
def setUp(self):
super(test_lp_1282584, self).setUp()
self.wizard_make_picking_obj = self.env['claim_make_picking.wizard']
line_obj = self.env['claim.line']
claim_obj = self.env['crm.claim']
self.product = self.env.ref('product.product_product_4')
self.partner = self.env.ref('base.res_partner_12')
# Create the claim with a claim line
self.claim = claim_obj.create(
{
'name': 'TEST CLAIM',
'number': 'TEST CLAIM',
'claim_type': 'customer',
'delivery_address_id': self.partner.id,
}
)
self.warehouse = self.claim.warehouse_id
self.claim_line = line_obj.create(
{
'name': 'TEST CLAIM LINE',
'claim_origine': 'none',
'product_id': self.product.id,
'claim_id': self.claim.id,
'location_dest_id': self.warehouse.lot_stock_id.id
}
)
def test_00(self):
""" Test wizard opened view model for a new product return """
context = {
'active_id': self.claim.id,
'partner_id': self.partner.id,
'warehouse_id': self.warehouse.id,
'picking_type': 'in',
}
wizard = self.wizard_make_picking_obj.with_context(context).create({})
res = wizard.action_create_picking()
self.assertEquals(res.get('res_model'), 'stock.picking',
"Wrong model defined")
def test_01(self):
""" Test wizard opened view model for a new delivery """
wizard_change_product_qty_obj = self.env['stock.change.product.qty']
context = {'active_id': self.product.id}
wizard_change_product_qty = wizard_change_product_qty_obj.create({
'product_id': self.product.id,
'new_quantity': 12
})
wizard_change_product_qty.with_context(context).change_product_qty()
context = {
'active_id': self.claim.id,
'partner_id': self.partner.id,
'warehouse_id': self.warehouse.id,
'picking_type': 'out',
}
wizard = self.wizard_make_picking_obj.with_context(context).create({})
res = wizard.action_create_picking()
self.assertEquals(res.get('res_model'), 'stock.picking',
"Wrong model defined")

View File

@@ -25,28 +25,28 @@
from openerp.models import api, TransientModel
from openerp.fields import Char
class AccountInvoiceRefund(TransientModel):
_inherit = "account.invoice.refund"
@api.one
def _get_description(self):
context = self.env.context
if context is None:
context = {}
description = context.get('description') or ''
self.description = description
return description
description = Char(default=_get_description)
@api.model
@api.one
def compute_refund(self, mode='refund'):
context = self.env.context
context = self.env.context.copy()
if context is None:
context = {}
if context.get('invoice_ids'):
context['active_ids'] = context.get('invoice_ids')
self = self.with_context(context)
return super(AccountInvoiceRefund, self).compute_refund(mode=mode)

View File

@@ -25,7 +25,10 @@
from openerp.models import api, TransientModel, _
from openerp.fields import Many2many, Many2one
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp import netsvc
from openerp.exceptions import Warning
from openerp import workflow
from openerp import workflow
import time
@@ -34,7 +37,6 @@ class ClaimMakePicking(TransientModel):
_description = 'Wizard to create pickings from claim lines'
# Get default source location
@api.one
def _get_source_loc(self):
loc_id = False
context = self.env.context
@@ -43,15 +45,16 @@ class ClaimMakePicking(TransientModel):
warehouse_obj = self.env['stock.warehouse']
warehouse_id = context.get('warehouse_id')
if context.get('picking_type') == 'out':
loc_id = warehouse_obj.read(
warehouse_id, ['lot_stock_id'])['lot_stock_id'][0]
elif context.get('partner_id'):
loc_id = self.env['res.partner'].read(
context['partner_id'], ['property_stock_customer']
)['property_stock_customer'][0]
picking_type = context.get('picking_type')
partner_id = context.get('partner_id')
if picking_type == 'out':
loc_id = warehouse_obj.browse(
warehouse_id).lot_stock_id.id
elif partner_id:
loc_id = self.env['res.partner'].browse(
partner_id).property_stock_customer.id
self.claim_line_source_location = loc_id
return loc_id
def _get_common_dest_location_from_line(self, line_ids):
"""Return the ID of the common location between all lines. If no common
@@ -70,7 +73,6 @@ class ClaimMakePicking(TransientModel):
return loc_id
# Get default destination location
@api.one
def _get_dest_loc(self):
"""Return the location_id to use as destination.
If it's an outoing shippment: take the customer stock property
@@ -81,20 +83,19 @@ class ClaimMakePicking(TransientModel):
context = {}
loc_id = False
if context.get('picking_type') == 'out' and context.get('partner_id'):
loc_id = self.env['res.partner'].read(
context.get('partner_id'), ['property_stock_customer']
)['property_stock_customer'][0]
elif context.get('picking_type') == 'in' and context.get('partner_id'):
picking_type = context.get('picking_type')
partner_id = context.get('partner_id')
if picking_type == 'out' and partner_id:
loc_id = self.env['res.partner'].browse(
partner_id).property_stock_customer.id
elif picking_type == 'in' and partner_id:
# Add the case of return to supplier !
line_ids = self._get_claim_lines()
loc_id = self._get_common_dest_location_from_line(line_ids)
self.claim_line_dest_location = loc_id
return loc_id
@api.one
def _get_claim_lines(self):
print "GET CLAIM LINES"
# TODO use custom states to show buttons of this wizard or not instead
# of raise an error
context = self.env.context
@@ -116,18 +117,18 @@ class ClaimMakePicking(TransientModel):
if not good_lines:
raise Warning(
_('Error'),
_('A picking has already been created for this claim.'))
print "LINES: ", good_lines
self.claim_line_ids = good_lines
return good_lines
claim_line_source_location = Many2one(
'stock.location', string='Source Location', required=True,
default='_get_source_loc',
default=_get_source_loc,
help="Location where the returned products are from.")
claim_line_dest_location = Many2one(
'stock.location', string='Dest. Location', required=True,
default='_get_dest_loc',
default=_get_dest_loc,
help="Location where the system will stock the returned products.")
claim_line_ids = Many2many(
'claim.line',
@@ -157,10 +158,10 @@ class ClaimMakePicking(TransientModel):
def action_cancel(self):
return {'type': 'ir.actions.act_window_close'}
# If "Create" button pressed
@api.model
@api.multi
def action_create_picking(self):
picking_obj = self.env['stock.picking']
picking_type_obj = self.env['stock.picking.type']
context = self.env.context
if context is None:
context = {}
@@ -168,26 +169,30 @@ class ClaimMakePicking(TransientModel):
view_obj = self.env['ir.ui.view']
name = 'RMA picking out'
if context.get('picking_type') == 'out':
p_type = 'out'
picking_type_code = 'outgoing'
write_field = 'move_out_id'
note = 'RMA picking out'
else:
p_type = 'in'
picking_type_code = 'incoming'
write_field = 'move_in_id'
if context.get('picking_type'):
note = 'RMA picking ' + str(context.get('picking_type'))
name = note
model = 'stock.picking.' + p_type
picking_type_id = picking_type_obj.search([
('code', '=', picking_type_code),
('default_location_dest_id', '=',
self.claim_line_dest_location.id)], limit=1).id
model = 'stock.picking'
view_id = view_obj.search([
('model', '=', model),
('type', '=', 'form')
], limit=1).id
('type', '=', 'form')], limit=1).id
claim = self.env['crm.claim'].browse(context['active_id'])
partner_id = claim.delivery_address_id.id
wizard = self
claim_lines = wizard.clame_line_ids
# line_ids = [x.id for x in wizard.claim_line_ids]
claim_lines = self.claim_line_ids
# In case of product return, we don't allow one picking for various
# product if location are different
@@ -197,6 +202,7 @@ class ClaimMakePicking(TransientModel):
claim_lines.ids)
if not common_dest_loc_id:
raise Warning(
_('Error'),
_('A product return cannot be created for various '
'destination locations, please choose line with a '
'same destination location.'))
@@ -207,6 +213,7 @@ class ClaimMakePicking(TransientModel):
if not common_dest_partner_id:
raise Warning(
_('Error'),
_('A product return cannot be created for various '
'destination addresses, please choose line with a '
'same address.'))
@@ -216,52 +223,50 @@ class ClaimMakePicking(TransientModel):
# create picking
picking = picking_obj.create(
{'origin': claim.number,
'type': p_type,
'picking_type_id': picking_type_id,
'move_type': 'one', # direct
'state': 'draft',
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'partner_id': partner_id,
'invoice_state': "none",
'company_id': claim.company_id.id,
'location_id': wizard.claim_line_source_location.id,
'location_dest_id': wizard.claim_line_dest_location.id,
'location_id': self.claim_line_source_location.id,
'location_dest_id': self.claim_line_dest_location.id,
'note': note,
'claim_id': claim.id,
}).id
})
# Create picking lines
fmt = DEFAULT_SERVER_DATETIME_FORMAT
for wizard_claim_line in wizard.claim_line_ids:
move_obj = self.env['stock.move']
move_id = move_obj.create(
{'name': wizard_claim_line.product_id.name_template,
'priority': '0',
'date': time.strftime(fmt),
'date_expected': time.strftime(fmt),
'product_id': wizard_claim_line.product_id.id,
'product_qty': wizard_claim_line.product_returned_quantity,
'product_uom': wizard_claim_line.product_id.uom_id.id,
'partner_id': partner_id,
'prodlot_id': wizard_claim_line.prodlot_id.id,
'picking_id': picking.id,
'state': 'draft',
'price_unit': wizard_claim_line.unit_sale_price,
'company_id': claim.company_id.id,
'location_id': wizard.claim_line_source_location.id,
'location_dest_id': wizard.claim_line_dest_location.id,
'note': note,
}).id
for line in self.claim_line_ids:
move_id = self.env['stock.move'].create({
'name': line.product_id.name_template,
'priority': '0',
'date': time.strftime(fmt),
'date_expected': time.strftime(fmt),
'product_id': line.product_id.id,
'product_uom_qty': line.product_returned_quantity,
'product_uom': line.product_id.product_tmpl_id.uom_id.id,
'partner_id': partner_id,
'picking_id': picking.id,
'state': 'draft',
'price_unit': line.unit_sale_price,
'company_id': claim.company_id.id,
'location_id': self.claim_line_source_location.id,
'location_dest_id': self.claim_line_dest_location.id,
'note': note}).id
wizard_claim_line.write({write_field: move_id})
line.write({write_field: move_id})
wf_service = netsvc.LocalService("workflow")
wf_service = workflow
if picking:
cr, uid = self.env.cr, self.env.uid
wf_service.trg_validate(uid, 'stock.picking',
picking.id, 'button_confirm', cr)
picking.action_assign()
domain = ("[('type', '=', '%s'), ('partner_id', '=', %s)]" %
(p_type, partner_id))
domain = ("[('picking_type_id.code', '=', '%s'), "
"('partner_id', '=', %s)]" % (picking_type_code, partner_id))
return {
'name': '%s' % name,
'view_type': 'form',
@@ -272,5 +277,3 @@ class ClaimMakePicking(TransientModel):
'res_id': picking.id,
'type': 'ir.actions.act_window',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: