avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00515
[Merge] lp:~mikelarregi/avanzosc/dos_refund_products into lp:~avanzosc-security-team/avanzosc/72horas
mikel arregi has proposed merging lp:~mikelarregi/avanzosc/dos_refund_products into lp:~avanzosc-security-team/avanzosc/72horas.
Requested reviews:
Avanzosc_security (avanzosc-security-team)
For more details, see:
https://code.launchpad.net/~mikelarregi/avanzosc/dos_refund_products/+merge/224626
dos_refund_products
--
https://code.launchpad.net/~mikelarregi/avanzosc/dos_refund_products/+merge/224626
Your team Avanzosc_security is requested to review the proposed merge of lp:~mikelarregi/avanzosc/dos_refund_products into lp:~avanzosc-security-team/avanzosc/72horas.
=== modified file 'dos_refund_products/__init__.py'
--- dos_refund_products/__init__.py 2014-06-11 10:23:47 +0000
+++ dos_refund_products/__init__.py 2014-06-26 13:37:14 +0000
@@ -19,8 +19,7 @@
#
##############################################################################
-import wizard
-import refund_products
-
+from . import wizard
+from . import models
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'dos_refund_products/__openerp__.py'
--- dos_refund_products/__openerp__.py 2014-06-11 10:23:47 +0000
+++ dos_refund_products/__openerp__.py 2014-06-26 13:37:14 +0000
@@ -21,21 +21,17 @@
{
- "name" : "DOS Refund Products",
- "version" : "1.0",
- "author" : "DOS",
- "category" : "Enterprise Specific Modules",
- "website" : "www.dos-sl.es",
+ "name": "DOS Refund Products",
+ "version": "1.0",
+ "author": "DOS",
+ "category": "Enterprise Specific Modules",
+ "website": "www.dos-sl.es",
"description": "This module allows refunds product and create pickings.",
- "depends" : ["base", "product", "stock", "dos_contracts"],
- "init_xml" : [],
- "update_xml" : [
- 'security/ir.model.access.csv',
- 'refund_products_view.xml',
- 'wizard/break_pack_product_view.xml',
- ],
- "active": False,
+ "depends": ["base", "product", "stock", "dos_contracts"],
+ "data": [
+ 'security/ir.model.access.csv',
+ 'views/refund_products_view.xml',
+ 'wizard/break_pack_product_view.xml',
+ ],
"installable": True
}
-
-
=== added directory 'dos_refund_products/models'
=== added file 'dos_refund_products/models/__init__.py'
--- dos_refund_products/models/__init__.py 1970-01-01 00:00:00 +0000
+++ dos_refund_products/models/__init__.py 2014-06-26 13:37:14 +0000
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 DOS (<http://www.dos-sl.es>).
+#
+# 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 . import refund_products
\ No newline at end of file
=== renamed file 'dos_refund_products/refund_products.py' => 'dos_refund_products/models/refund_products.py'
--- dos_refund_products/refund_products.py 2014-06-11 10:23:47 +0000
+++ dos_refund_products/models/refund_products.py 2014-06-26 13:37:14 +0000
@@ -19,452 +19,546 @@
#
##############################################################################
-from osv import osv
+from openerp.osv import orm, fields
from osv import fields
from tools.translate import _
import time
import netsvc
-class refund_products(osv.osv):
-
- _name = 'refund.products'
- _description = "Refund Products"
-
- _columns = {
- 'date': fields.datetime('Date', required=True),
- 'picking_in_id': fields.many2one('stock.picking', 'In Picking', readonly=True),
- 'picking_out_id': fields.many2one('stock.picking', 'Out Picking', readonly=True),
- 'refund_product_ids': fields.one2many('refund.product', 'refund_id', 'Refund Products'),
- 'state': fields.selection( ( ('draft','Draft'), ('done','Done'),), readonly=True ),
- }
-
- _defaults = {
- 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
- 'state': lambda *a: 'draft',
- }
-
- _order = 'date desc'
-
-
- def _get_pack_products(self, cr, uid, stock_warehouse, pack_product, pack_production_lot):
-
- sale_obj = self.pool.get('sale.order')
- #stock_picking_obj = self.pool.get('stock.picking')
- #stock_move_obj = self.pool.get('stock.move')
- bom_obj = self.pool.get('mrp.bom')
- product_obj = self.pool.get('product.product')
-
- sim_product_id = None
- sim_production_lot_id = None
- link_product_id = None
- link_production_lot_id = None
-
- # Si el producto tiene como metodo suministro producir (Pack)
- # Creamos lineas con los materiales que lo componen
- if pack_product and pack_product.supply_method == 'produce':
-
- bom_id = bom_obj._bom_find(cr, uid, pack_product.id, pack_product.uom_id and pack_product.uom_id.id, [])
-
- if bom_id:
- bom_point = bom_obj.browse(cr, uid, bom_id, context={})
-
- if bom_point.bom_lines:
-
- #Recorremos materiales
- for bom_line in bom_point.bom_lines:
- prodlot_id = sale_obj._get_bom_product_lot(cr, uid, stock_warehouse, pack_production_lot.id, bom_line.product_id.id)
-
- #Si es SIM
- if product_obj._is_sim(bom_line.product_id.categ_id):
- sim_product_id = bom_line.product_id.id
- sim_production_lot_id = prodlot_id
-
- #Si es Enlace
- elif product_obj._is_link(bom_line.product_id.categ_id):
- link_product_id = bom_line.product_id.id
- link_production_lot_id = prodlot_id
-
- return sim_product_id, sim_production_lot_id, link_product_id, link_production_lot_id
-
-
- def picking_processing(self, cr, uid, picking_ids, date, context=None):
- """ Makes partial moves and pickings done."""
-
- pick_obj = self.pool.get('stock.picking')
-
- partial_datas = {
- 'delivery_date' : date
- }
-
- for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
-
- for move in pick.move_lines:
- partial_datas['move%s' % (move.id)] = {
- 'product_id': move.product_id.id,
- 'product_qty': move.product_qty,
- 'product_uom': move.product_uom.id,
- 'prodlot_id': move.prodlot_id.id,
- }
-
- pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
-
-
- def button_done(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
-
- stock_warehouse_obj = self.pool.get('stock.warehouse')
- prod_obj = self.pool.get('product.product')
- pick_obj = self.pool.get('stock.picking')
- move_obj = self.pool.get('stock.move')
- prodlot_obj = self.pool.get('stock.production.lot')
- uom_obj = self.pool.get('product.uom')
- annexe_obj = self.pool.get('contract.annexe')
- wf_service = netsvc.LocalService("workflow")
-
-
- #Comprobamos que hay al menos un almacen definido
- stock_warehouse = None
- stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
-
- for warehouse in stock_warehouse_obj.browse(cr, uid, stock_warehouse_ids, context):
- stock_warehouse = warehouse
- break
-
- if not stock_warehouse:
- raise osv.except_osv(_('Stock Warehouse not defined !'), _('Stock Warehouse not defined.'))
-
-
- data = self.browse(cr, uid, ids, context=context)
-
- for refund_products in data:
-
- date_cur = refund_products.date
-
- if refund_products.refund_product_ids and refund_products.state in ('draft',):
-
- origin_partner = None
- new_picking_in = None
- new_picking_out = None
-
- for prod in refund_products.refund_product_ids:
-
- # Validaciones
- if prod_obj._is_sim(prod.product_id.categ_id) and prod_obj._is_sim(prod.refund_product_id.categ_id):
- annexe_ids = annexe_obj.search(cr, uid, [("product_id", "=", prod.product_id.id), ("production_lot_id", "=", prod.prodlot_id.id), ("active_annexe", "=", True)])
- annexe_subs_ids = annexe_obj.search(cr, uid, [("product_id", "=", prod.refund_product_id.id), ("production_lot_id", "=", prod.refund_prodlot_id.id), ("active_annexe", "=", True)])
-
- elif prod_obj._is_link(prod.product_id.categ_id) and prod_obj._is_link(prod.refund_product_id.categ_id):
- annexe_ids = annexe_obj.search(cr, uid, [("product_2_id", "=", prod.product_id.id), ("production_lot_2_id", "=", prod.prodlot_id.id), ("active_annexe", "=", True)])
- annexe_subs_ids = annexe_obj.search(cr, uid, [("product_2_id", "=", prod.refund_product_id.id), ("production_lot_2_id", "=", prod.refund_prodlot_id.id), ("active_annexe", "=", True)])
-
- elif prod_obj._is_pack(prod.product_id.categ_id) and prod_obj._is_pack(prod.refund_product_id.categ_id):
- annexe_ids = annexe_obj.search(cr, uid, [("pack_product_id", "=", prod.product_id.id), ("pack_production_lot_id", "=", prod.prodlot_id.id), ("active_annexe", "=", True)])
- annexe_subs_ids = annexe_obj.search(cr, uid, [("pack_product_id", "=", prod.refund_product_id.id), ("pack_production_lot_id", "=", prod.refund_prodlot_id.id), ("active_annexe", "=", True)])
-
- else:
- raise osv.except_osv(_('Error !'), _('Can not return products with different category.'))
-
- annexe_id = annexe_ids and annexe_ids[0] or None
- annexe_subs_id = annexe_subs_ids and annexe_subs_ids[0] or None
-
- #Obtenemos movimiento de salida del producto devuelto
- refund_prodlot = prod.refund_prodlot_id
- move = refund_prodlot.move_ids and refund_prodlot.move_ids[0] or None
-
- for m in refund_prodlot.move_ids:
- if m.location_id.id == stock_warehouse.lot_stock_id.id and m.picking_id:
- move = m
- break
-
- #Obtenemos movimiento de entrada del producto sustitucion
- subs_prodlot = prod.prodlot_id
- move_subs = subs_prodlot.move_ids and subs_prodlot.move_ids[0] or None
-
- for m in subs_prodlot.move_ids:
- if m.location_dest_id.id == stock_warehouse.lot_stock_id.id:
- move_subs = m
- break
-
- #Evitamos que se devuelvan productos procedentes de distintos clientes
- if origin_partner and move and move.picking_id.partner_id and origin_partner != move.picking_id.partner_id.id:
- raise osv.except_osv(_('Error !'), _('Can not return products from different partner.'))
-
- if move and move.state == 'done' and move.picking_id.type in ('internal', 'out'):
-
- origin_partner = move.picking_id.partner_id and move.picking_id.partner_id.id or None
-
- # Comprobamos que el articulo de sustitución no está asignado ya en un anexo.
- # En el caso que lo esté, intercambiamos productos entre ellos.
- if annexe_id and annexe_subs_id:
-
- annexe = annexe_obj.browse(cr, uid, annexe_id, context)
-
- pack_product_id = annexe.pack_product_id.id
- pack_production_lot_id = annexe.pack_production_lot_id.id
- product_id = annexe.product_id.id
- production_lot_id = annexe.production_lot_id.id
- product_2_id = annexe.product_2_id.id
- production_lot_2_id = annexe.production_lot_2_id.id
-
- annexe_subs = annexe_obj.browse(cr, uid, annexe_subs_id, context)
-
- subs_pack_product_id = annexe_subs.pack_product_id.id
- subs_pack_production_lot_id = annexe_subs.pack_production_lot_id.id
- subs_product_id = annexe_subs.product_id.id
- subs_production_lot_id = annexe_subs.production_lot_id.id
- subs_product_2_id = annexe_subs.product_2_id.id
- subs_production_lot_2_id = annexe_subs.production_lot_2_id.id
-
- # Intercambiamos productos entre anexos
- vals = {}
-
- # SIM
- if prod_obj._is_sim(prod.refund_product_id.categ_id):
- vals = {'product_id': prod.refund_product_id.id, 'production_lot_id': prod.refund_prodlot_id.id}
- # Enlace
- elif prod_obj._is_link(prod.refund_product_id.categ_id):
- vals = {'product_2_id': prod.refund_product_id.id, 'production_lot_2_id': prod.refund_prodlot_id.id}
- # Pack
- elif prod_obj._is_pack(prod.refund_product_id.categ_id):
- # Obtenemos productos que forman el pack
- #product_id, production_lot_id, product_2_id, production_lot_2_id = self._get_pack_products(cr, uid, stock_warehouse, prod.refund_product_id, prod.refund_prodlot_id)
-
- vals = {'pack_product_id': subs_pack_product_id,
- 'pack_production_lot_id': subs_pack_production_lot_id,
- 'product_id': subs_product_id,
- 'production_lot_id': subs_production_lot_id,
- 'product_2_id': subs_product_2_id,
- 'production_lot_2_id': subs_production_lot_2_id,
- }
-
- if vals:
- annexe_obj.write(cr, uid, [annexe_id], vals)
-
-
- vals_subs = {}
-
- # SIM
- if prod_obj._is_sim(prod.product_id.categ_id):
- vals_subs = {'product_id': prod.product_id.id, 'production_lot_id': prod.prodlot_id.id}
- # Enlace
- elif prod_obj._is_link(prod.product_id.categ_id):
- vals_subs = {'product_2_id': prod.product_id.id, 'production_lot_2_id': prod.prodlot_id.id}
- # Pack
- elif prod_obj._is_pack(prod.product_id.categ_id):
- # Obtenemos productos que forman el pack
- #product_id, production_lot_id, product_2_id, production_lot_2_id = self._get_pack_products(cr, uid, stock_warehouse, prod.product_id, prod.prodlot_id)
-
- vals_subs = {'pack_product_id': pack_product_id,
- 'pack_production_lot_id': pack_production_lot_id,
- 'product_id': product_id,
- 'production_lot_id': production_lot_id,
- 'product_2_id': product_2_id,
- 'production_lot_2_id': production_lot_2_id,
- }
-
- if vals_subs:
- annexe_obj.write(cr, uid, [annexe_subs_id], vals_subs)
-
- else:
- # Obtenemos datos del anexo o en su defecto del movimiento
- annexe_subs = annexe_subs_id and annexe_obj.browse(cr, uid, annexe_subs_id) or None
- contract_subs = annexe_subs and annexe_subs.contract_id or None
-
- picking_vals = {
- 'partner_id':contract_subs and contract_subs.customer_id.id or move.picking_id.partner_id.id,
- 'address_id':contract_subs and contract_subs.customer_address_id.id or move.picking_id.address_id.id,
- 'elevator_partner_id':contract_subs and contract_subs.elevator_id and contract_subs.elevator_id.id or (move.picking_id.elevator_partner_id and move.picking_id.elevator_partner_id.id or None),
- 'elevator_invoice_id':contract_subs and contract_subs.elevator_address_id and contract_subs.elevator_address_id.id or (move.picking_id.elevator_invoice_id and move.picking_id.elevator_invoice_id.id or None),
- 'middleman_partner_id':contract_subs and contract_subs.middleman_id and contract_subs.middleman_id.id or (move.picking_id.middleman_partner_id and move.picking_id.middleman_partner_id.id or None),
- 'contract_id':contract_subs and contract_subs.id or (move.picking_id.contract_id and move.picking_id.contract_id.id or None),
- }
-
- #Creamos albaran de entrada con los productos devueltos
- if not new_picking_in:
- type = 'in'
-
- vals = {#'name':'%s-return' % move.picking_id.name,
- 'name':self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.in'),
- 'move_lines':[],
- 'state':'draft',
- 'type':type,
- 'date':date_cur,
- 'invoice_state':'none',
- }
-
- vals.update(picking_vals)
-
- new_picking_in = pick_obj.copy(cr, uid, move.picking_id.id, vals)
-
- #Creamos lineas de albarán de entrada
- new_location=move.location_dest_id.id
- new_qty = 1
-
- vals = {
- 'product_qty': new_qty,
- 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id, new_qty, move.product_uos.id),
- 'picking_id':new_picking_in,
- 'state':'draft',
- 'location_id':new_location,
- 'location_dest_id':prod.location_dest_id and prod.location_dest_id.id or move.location_id.id,
- 'date':date_cur,}
-
- new_move = move_obj.copy(cr, uid, move.id, vals)
- move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
-
-
- #Creamos albaran de salida con los productos sustituidos
- if not new_picking_out:
- type = 'out'
-
- vals = {#'name':'%s-replace' % move.picking_id.name,
- 'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out'),
- 'move_lines':[],
- 'state':'draft',
- 'type':type,
- 'date':date_cur,
- 'invoice_state':'none',
- }
-
- vals.update(picking_vals)
-
- new_picking_out = pick_obj.copy(cr, uid, move.picking_id.id, vals)
-
- #Creamos lineas de albarán de salida
- # Los almacenes de destino serán los mismos que los del movimiento origen de la sustitucion
- # Cambia producto y lote
- new_qty = 1
- new_product_id = prod.product_id.id
- new_prodlot_id = prod.prodlot_id.id
-
- vals = {
- 'product_qty': new_qty,
- 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id, new_qty, move.product_uos.id),
- 'picking_id':new_picking_out,
- 'state':'draft',
- 'product_id':new_product_id,
- 'prodlot_id':new_prodlot_id,
- 'date':date_cur,
- 'contract_id':contract_subs and contract_subs.id or None,
- 'contract_annexe_id':annexe_subs and annexe_subs.id or None,
- }
-
- new_move = move_obj.copy(cr, uid, move.id, vals)
- #move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
-
- #Actualizamos anexo con los nuevos productos sustituidos
- if annexe_subs_id:
- vals = {}
-
- # SIM
- if prod_obj._is_sim(prod.product_id.categ_id):
- vals = {'product_id': new_product_id, 'production_lot_id': new_prodlot_id}
- # Enlace
- elif prod_obj._is_link(prod.product_id.categ_id):
- vals = {'product_2_id': new_product_id, 'production_lot_2_id': new_prodlot_id}
- # Pack
- elif prod_obj._is_pack(prod.product_id.categ_id):
- # Obtenemos productos que forman el pack
- product_id, production_lot_id, product_2_id, production_lot_2_id = self._get_pack_products(cr, uid, stock_warehouse, prod.product_id, prod.prodlot_id)
-
- vals = {'pack_product_id': new_product_id,
- 'pack_production_lot_id': new_prodlot_id,
- 'product_id': product_id,
- 'production_lot_id': production_lot_id,
- 'product_2_id': product_2_id,
- 'production_lot_2_id': production_lot_2_id,
- }
-
- if vals:
- annexe_obj.write(cr, uid, [annexe_subs_id], vals)
-
-
- """
- if not new_picking_in or not new_picking_out:
-
- raise osv.except_osv(_('Error !'), _('Could not make the return of the products.'))
- """
-
- if new_picking_in:
-
- #Confirmamos albarán de entrada
- wf_service.trg_validate(uid, 'stock.picking', new_picking_in, 'button_confirm', cr)
- pick_obj.force_assign(cr, uid, [new_picking_in], context)
-
- #Procesamos albarán de entrada
- self.picking_processing(cr, uid, [new_picking_in], date_cur, context)
-
- if new_picking_out:
-
- #Confirmamos albarán de salida
- wf_service.trg_validate(uid, 'stock.picking', new_picking_out, 'button_confirm', cr)
- pick_obj.force_assign(cr, uid, [new_picking_out], context)
-
- #Procesamos albarán de entrada
- self.picking_processing(cr, uid, [new_picking_out], date_cur, context)
-
- else:
- raise osv.except_osv(_('Error !'), _('There are no products to return.'))
-
- return self.write(cr, uid, ids, {'state':'done',
- 'picking_in_id': new_picking_in,
- 'picking_out_id': new_picking_out}, context=context)
-
-refund_products()
-
-
-class refund_product(osv.osv):
-
- _name = 'refund.product'
- _description = "Refund Product"
-
- _columns = {
- 'refund_id': fields.many2one('refund.products', 'Refund Products', select=True, required=True),
- 'refund_product_id': fields.many2one('product.product', 'Refund Product', select=True, required=True),
- 'refund_prodlot_id': fields.many2one('stock.production.lot', 'Refund Product Lot', select=True, required=True),
- 'product_id': fields.many2one('product.product', 'Substitution Product', select=True, required=True),
- 'prodlot_id': fields.many2one('stock.production.lot', 'Substitution Product Lot', select=True, required=True),
- 'location_id': fields.many2one('stock.location', 'Source Location', select=True, store=True, required=True),
- 'location_dest_id': fields.many2one('stock.location', 'Destination Location', required=True),
- }
-
- def onchange_refund_product(self, cr, uid, ids, product_id=False, prodlot_id=False):
- if not product_id or not prodlot_id:
- return {'value': {'location_id': False, 'location_dest_id': False}}
-
-
- stock_warehouse_obj = self.pool.get('stock.warehouse')
- prodlot_obj = self.pool.get('stock.production.lot')
-
- #Comprobamos que hay al menos un almacen definido
- stock_warehouse = None
- stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
-
- for warehouse in stock_warehouse_obj.browse(cr, uid, stock_warehouse_ids, context=None):
- stock_warehouse = warehouse
- break
-
- if not stock_warehouse:
- raise osv.except_osv(_('Stock Warehouse not defined !'), _('Stock Warehouse not defined.'))
-
- #Obtenemos movimiento de salida del producto devuelto
- prodlot = prodlot_obj.browse(cr, uid, prodlot_id)
-
- move = prodlot.move_ids and prodlot.move_ids[0] or None
-
- for m in prodlot.move_ids:
- if m.location_id.id == stock_warehouse.lot_stock_id.id and m.picking_id:
- move = m
- break
-
- val = {
- 'location_id': move and move.location_dest_id and move.location_dest_id.id or False,
- 'location_dest_id': stock_warehouse.lot_stock_id.id,
- }
-
- return {'value': val}
-
-refund_product()
-
-
+
+class RefundProducts(orm.Model):
+ _name = 'refund.products'
+ _description = "Refund Products"
+ _columns = {
+ 'date': fields.datetime('Date', required=True),
+ 'picking_in_id': fields.many2one('stock.picking', 'In Picking',
+ readonly=True),
+ 'picking_out_id': fields.many2one('stock.picking', 'Out Picking',
+ readonly=True),
+ 'refund_product_ids': fields.one2many('refund.product', 'refund_id',
+ 'Refund Products'),
+ 'state': fields.selection((('draft', 'Draft'), ('done', 'Done'), ),
+ readonly=True),
+ }
+ _defaults = {
+ 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'state': lambda *a: 'draft',
+ }
+ _order = 'date desc'
+
+ def _get_pack_products(self, cr, uid, stock_warehouse, pack_product,
+ pack_production_lot):
+ sale_obj = self.pool['sale.order']
+ # stock_picking_obj = self.pool.get('stock.picking')
+ # stock_move_obj = self.pool.get('stock.move')
+ bom_obj = self.pool['mrp.bom']
+ product_obj = self.pool['product.product']
+ sim_product_id = None
+ sim_production_lot_id = None
+ link_product_id = None
+ link_production_lot_id = None
+ # Si el producto tiene como metodo suministro producir (Pack)
+ # Creamos lineas con los materiales que lo componen
+ if pack_product and pack_product.supply_method == 'produce':
+ bom_id = bom_obj._bom_find(cr, uid, pack_product.id,
+ (pack_product.uom_id and
+ pack_product.uom_id.id), [])
+ if bom_id:
+ bom_point = bom_obj.browse(cr, uid, bom_id, context={})
+ if bom_point.bom_lines:
+ # Recorremos materiales
+ for bom_line in bom_point.bom_lines:
+ prodlot_id = sale_obj._get_bom_product_lot(
+ cr, uid, stock_warehouse, pack_production_lot.id,
+ bom_line.product_id.id)
+ # Si es SIM
+ if product_obj._is_sim(bom_line.product_id.categ_id):
+ sim_product_id = bom_line.product_id.id
+ sim_production_lot_id = prodlot_id
+ # Si es Enlace
+ elif product_obj._is_link(
+ bom_line.product_id.categ_id):
+ link_product_id = bom_line.product_id.id
+ link_production_lot_id = prodlot_id
+ return (sim_product_id, sim_production_lot_id, link_product_id,
+ link_production_lot_id)
+
+ def picking_processing(self, cr, uid, picking_ids, date, context=None):
+ """ Makes partial moves and pickings done."""
+ pick_obj = self.pool['stock.picking']
+ partial_datas = {
+ 'delivery_date': date
+ }
+ for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
+ for move in pick.move_lines:
+ partial_datas['move%s' % (move.id)] = {
+ 'product_id': move.product_id.id,
+ 'product_qty': move.product_qty,
+ 'product_uom': move.product_uom.id,
+ 'prodlot_id': move.prodlot_id.id,
+ }
+ pick_obj.do_partial(cr, uid, picking_ids, partial_datas,
+ context=context)
+
+ def button_done(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
+ stock_warehouse_obj = self.pool['stock.warehouse']
+ prod_obj = self.pool['product.product']
+ pick_obj = self.pool['stock.picking']
+ move_obj = self.pool['stock.move']
+ prodlot_obj = self.pool['stock.production.lot']
+ uom_obj = self.pool['product.uom']
+ annexe_obj = self.pool['contract.annexe']
+ wf_service = netsvc.LocalService("workflow")
+ # Comprobamos que hay al menos un almacen definido
+ stock_warehouse = None
+ stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
+ for warehouse in stock_warehouse_obj.browse(cr, uid,
+ stock_warehouse_ids,
+ context):
+ stock_warehouse = warehouse
+ break
+ if not stock_warehouse:
+ raise orm.except_orm(_('Stock Warehouse not defined !'),
+ _('Stock Warehouse not defined.'))
+ data = self.browse(cr, uid, ids, context=context)
+ for refund_products in data:
+ date_cur = refund_products.date
+ if (refund_products.refund_product_ids and
+ refund_products.state in ('draft',)):
+ origin_partner = None
+ new_picking_in = None
+ new_picking_out = None
+ for prod in refund_products.refund_product_ids:
+ # Validaciones
+ if (prod_obj._is_sim(prod.product_id.categ_id) and
+ prod_obj._is_sim(prod.refund_product_id.categ_id)):
+ annexe_ids = annexe_obj.search(
+ cr, uid, [("product_id", "=", prod.product_id.id),
+ ("production_lot_id", "=",
+ prod.prodlot_id.id),
+ ("active_annexe", "=", True)])
+ annexe_subs_ids = annexe_obj.search(
+ cr, uid, [("product_id", "=",
+ prod.refund_product_id.id),
+ ("production_lot_id", "=",
+ prod.refund_prodlot_id.id),
+ ("active_annexe", "=", True)])
+ elif (prod_obj._is_link(prod.product_id.categ_id) and
+ prod_obj._is_link(
+ prod.refund_product_id.categ_id)):
+ annexe_ids = annexe_obj.search(
+ cr, uid,
+ [("product_2_id", "=", prod.product_id.id),
+ ("production_lot_2_id", "=", prod.prodlot_id.id),
+ ("active_annexe", "=", True)])
+ annexe_subs_ids = annexe_obj.search(
+ cr, uid, [("product_2_id", "=",
+ prod.refund_product_id.id),
+ ("production_lot_2_id", "=",
+ prod.refund_prodlot_id.id),
+ ("active_annexe", "=", True)])
+ elif (prod_obj._is_pack(prod.product_id.categ_id) and
+ prod_obj._is_pack(
+ prod.refund_product_id.categ_id)):
+ annexe_ids = (annexe_obj.search(
+ cr, uid, [("pack_product_id", "=",
+ prod.product_id.id),
+ ("pack_production_lot_id", "=",
+ prod.prodlot_id.id),
+ ("active_annexe", "=", True)]))
+ annexe_subs_ids = annexe_obj.search(
+ cr, uid, [("pack_product_id", "=",
+ prod.refund_product_id.id),
+ ("pack_production_lot_id", "=",
+ prod.refund_prodlot_id.id),
+ ("active_annexe", "=", True)])
+ else:
+ raise orm.except_orm(_('Error !'),
+ _('Can not return products'
+ ' with different category.'))
+ annexe_id = annexe_ids and annexe_ids[0] or None
+ annexe_subs_id = (annexe_subs_ids and annexe_subs_ids[0]
+ or None)
+ # Obtenemos movimiento de salida del producto devuelto
+ refund_prodlot = prod.refund_prodlot_id
+ move = (refund_prodlot.move_ids and
+ refund_prodlot.move_ids[0] or None)
+ for m in refund_prodlot.move_ids:
+ if m.location_id.id == (stock_warehouse.lot_stock_id.id
+ and m.picking_id):
+ move = m
+ break
+ # Obtenemos movimiento de entrada del producto sustitucion
+ subs_prodlot = prod.prodlot_id
+ move_subs = (subs_prodlot.move_ids and
+ subs_prodlot.move_ids[0] or None)
+ for m in subs_prodlot.move_ids:
+ if (m.location_dest_id.id ==
+ stock_warehouse.lot_stock_id.id):
+ move_subs = m
+ break
+ # Evitamos que se devuelvan productos
+ # procedentes de distintos clientes
+ if (origin_partner and move and move.picking_id.partner_id
+ and origin_partner !=
+ move.picking_id.partner_id.id):
+ raise orm.except_orm(_('Error !'),
+ _('Can not return products '
+ 'from different partner.'))
+ if move and move.state == ('done' and move.picking_id.type
+ in ('internal', 'out')):
+ origin_partner = (move.picking_id.partner_id and
+ move.picking_id.partner_id.id
+ or None)
+ # Comprobamos que el articulo de sustitución
+ # no está asignado ya en un anexo. En el caso
+ # que lo esté, intercambiamos productos entre ellos.
+ if annexe_id and annexe_subs_id:
+ annexe = annexe_obj.browse(cr, uid, annexe_id,
+ context)
+ pack_product_id = annexe.pack_product_id.id
+ pack_production_lot_id = (
+ annexe.pack_production_lot_id.id)
+ product_id = annexe.product_id.id
+ production_lot_id = annexe.production_lot_id.id
+ product_2_id = annexe.product_2_id.id
+ production_lot_2_id = annexe.production_lot_2_id.id
+ annexe_subs = annexe_obj.browse(
+ cr, uid, annexe_subs_id, context)
+ subs_pack_product_id = (
+ annexe_subs.pack_product_id.id)
+ subs_pack_production_lot_id = (
+ annexe_subs.pack_production_lot_id.id)
+ subs_product_id = annexe_subs.product_id.id
+ subs_production_lot_id = (
+ annexe_subs.production_lot_id.id)
+ subs_product_2_id = annexe_subs.product_2_id.id
+ subs_production_lot_2_id = (
+ annexe_subs.production_lot_2_id.id)
+ # Intercambiamos productos entre anexos
+ vals = {}
+ # SIM
+ if prod_obj._is_sim(
+ prod.refund_product_id.categ_id):
+ vals = {
+ 'product_id':
+ prod.refund_product_id.id,
+ 'production_lot_id':
+ prod.refund_prodlot_id.id
+ }
+ # Enlace
+ elif prod_obj._is_link(
+ prod.refund_product_id.categ_id):
+ vals = {
+ 'product_2_id': prod.refund_product_id.id,
+ 'production_lot_2_id':
+ prod.refund_prodlot_id.id
+ }
+ # Pack
+ elif prod_obj._is_pack(
+ prod.refund_product_id.categ_id):
+ # Obtenemos productos que forman el pack
+ # product_id, production_lot_id, product_2_id,
+ # production_lot_2_id = self._get_pack_products
+ # (cr, uid, stock_warehouse, prod.
+ # refund_product_id, prod.refund_prodlot_id)
+ vals = {
+ 'pack_product_id': subs_pack_product_id,
+ 'pack_production_lot_id':
+ subs_pack_production_lot_id,
+ 'product_id': subs_product_id,
+ 'production_lot_id':
+ subs_production_lot_id,
+ 'product_2_id': subs_product_2_id,
+ 'production_lot_2_id':
+ subs_production_lot_2_id,
+ }
+ if vals:
+ annexe_obj.write(cr, uid, [annexe_id], vals)
+ vals_subs = {}
+ # SIM
+ if prod_obj._is_sim(prod.product_id.categ_id):
+ vals_subs = {
+ 'product_id': prod.product_id.id,
+ 'production_lot_id': prod.prodlot_id.id
+ }
+ # Enlace
+ elif prod_obj._is_link(prod.product_id.categ_id):
+ vals_subs = {
+ 'product_2_id': prod.product_id.id,
+ 'production_lot_2_id': prod.prodlot_id.id
+ }
+ # Pack
+ elif prod_obj._is_pack(prod.product_id.categ_id):
+ # Obtenemos productos que forman el pack
+ # product_id, production_lot_id, product_2_id,
+ # production_lot_2_id = self._get_pack_products
+ # (cr, uid, stock_warehouse, prod.product_id,
+ # prod.prodlot_id)
+ vals_subs = {
+ 'pack_product_id': pack_product_id,
+ 'pack_production_lot_id':
+ pack_production_lot_id,
+ 'product_id': product_id,
+ 'production_lot_id': production_lot_id,
+ 'product_2_id': product_2_id,
+ 'production_lot_2_id': production_lot_2_id,
+ }
+ if vals_subs:
+ annexe_obj.write(cr, uid, [annexe_subs_id],
+ vals_subs)
+ else:
+ # Obtenemos datos del anexo
+ # o en su defecto del movimiento
+ annexe_subs = (annexe_subs_id and
+ annexe_obj.browse(cr, uid,
+ annexe_subs_id)
+ or None)
+ contract_subs = (annexe_subs and
+ annexe_subs.contract_id or None)
+ picking_vals = {
+ 'partner_id': (
+ contract_subs and
+ contract_subs.customer_id.id or
+ move.picking_id.partner_id.id),
+ 'address_id': (
+ contract_subs and
+ contract_subs.customer_address_id.id or
+ move.picking_id.address_id.id),
+ 'elevator_partner_id': (
+ contract_subs and
+ contract_subs.elevator_id and
+ contract_subs.elevator_id.id or
+ (move.picking_id.elevator_partner_id and
+ move.picking_id.elevator_partner_id.id
+ or None)),
+ 'elevator_invoice_id': (
+ contract_subs and
+ contract_subs.elevator_address_id and
+ contract_subs.elevator_address_id.id or
+ (move.picking_id.elevator_invoice_id and
+ move.picking_id.elevator_invoice_id.id
+ or None)),
+ 'middleman_partner_id': (
+ contract_subs and
+ contract_subs.middleman_id and
+ contract_subs.middleman_id.id or
+ (move.picking_id.middleman_partner_id and
+ move.picking_id.middleman_partner_id.id
+ or None)),
+ 'contract_id': (
+ contract_subs and contract_subs.id or
+ (move.picking_id.contract_id and
+ move.picking_id.contract_id.id or None)),
+ }
+ # Creamos albaran de entrada con
+ # los productos devueltos
+ if not new_picking_in:
+ type = 'in'
+ vals = {
+ # 'name':'%s-return' %
+ # move.picking_id.name,
+ 'name': self.pool['ir.sequence'].get(
+ cr, uid, 'stock.picking.in'),
+ 'move_lines': [],
+ 'state': 'draft',
+ 'type': type,
+ 'date': date_cur,
+ 'invoice_state': 'none',
+ }
+ vals.update(picking_vals)
+ new_picking_in = pick_obj.copy(
+ cr, uid, move.picking_id.id, vals)
+ # Creamos lineas de albarán de entrada
+ new_location = move.location_dest_id.id
+ new_qty = 1
+ vals = {
+ 'product_qty': new_qty,
+ 'product_uos_qty': uom_obj._compute_qty(
+ cr, uid, move.product_uom.id, new_qty,
+ move.product_uos.id),
+ 'picking_id': new_picking_in,
+ 'state': 'draft',
+ 'location_id': new_location,
+ 'location_dest_id': (
+ prod.location_dest_id and
+ prod.location_dest_id.id or
+ move.location_id.id),
+ 'date': date_cur}
+ new_move = move_obj.copy(cr, uid, move.id, vals)
+ move_obj.write(cr, uid, [move.id],
+ {'move_history_ids2':
+ [(4, new_move)]})
+ # Creamos albaran de salida
+ # con los productos sustituidos
+ if not new_picking_out:
+ type = 'out'
+ vals = {
+ # 'name':'%s-replace' %
+ # move.picking_id.name,
+ 'name': self.pool['ir.sequence'].get(
+ cr, uid, 'stock.picking.out'),
+ 'move_lines': [],
+ 'state': 'draft',
+ 'type': type,
+ 'date': date_cur,
+ 'invoice_state': 'none',
+ }
+ vals.update(picking_vals)
+ new_picking_out = pick_obj.copy(
+ cr, uid, move.picking_id.id, vals)
+ # Creamos lineas de albarán de salida
+ # Los almacenes de destino serán los mismos que
+ # los del movimiento origen de la sustitucion
+ # Cambia producto y lote
+ new_qty = 1
+ new_product_id = prod.product_id.id
+ new_prodlot_id = prod.prodlot_id.id
+ vals = {
+ 'product_qty': new_qty,
+ 'product_uos_qty': uom_obj._compute_qty(
+ cr, uid, move.product_uom.id, new_qty,
+ move.product_uos.id),
+ 'picking_id': new_picking_out,
+ 'state': 'draft',
+ 'product_id': new_product_id,
+ 'prodlot_id': new_prodlot_id,
+ 'date': date_cur,
+ 'contract_id': (contract_subs and
+ contract_subs.id or None),
+ 'contract_annexe_id': (annexe_subs and
+ annexe_subs.id or None),
+ }
+ new_move = move_obj.copy(cr, uid, move.id, vals)
+ # move_obj.write(cr, uid, [move.id],
+ # {'move_history_ids2':[(4,new_move)]})
+ # Actualizamos anexo con
+ # los nuevos productos sustituidos
+ if annexe_subs_id:
+ vals = {}
+ # SIM
+ if prod_obj._is_sim(prod.product_id.categ_id):
+ vals = {
+ 'product_id': new_product_id,
+ 'production_lot_id': new_prodlot_id
+ }
+ # Enlace
+ elif prod_obj._is_link(
+ prod.product_id.categ_id):
+ vals = {
+ 'product_2_id': new_product_id,
+ 'production_lot_2_id': new_prodlot_id
+ }
+ # Pack
+ elif prod_obj._is_pack(
+ prod.product_id.categ_id):
+ # Obtenemos productos que forman el pack
+ (product_id, production_lot_id,
+ product_2_id, production_lot_2_id) = (
+ self._get_pack_products(
+ cr, uid, stock_warehouse,
+ prod.product_id, prod.prodlot_id))
+ vals = {
+ 'pack_product_id': new_product_id,
+ 'pack_production_lot_id':
+ new_prodlot_id,
+ 'product_id': product_id,
+ 'production_lot_id':
+ production_lot_id,
+ 'product_2_id': product_2_id,
+ 'production_lot_2_id':
+ production_lot_2_id,
+ }
+ if vals:
+ annexe_obj.write(cr, uid, [annexe_subs_id],
+ vals)
+ """
+ if not new_picking_in or not new_picking_out:
+ raise osv.except_osv(_('Error !'),
+ _('Could not make the return of the products.'))
+ """
+ if new_picking_in:
+ # Confirmamos albarán de entrada
+ wf_service.trg_validate(uid, 'stock.picking',
+ new_picking_in,
+ 'button_confirm', cr)
+ pick_obj.force_assign(cr, uid, [new_picking_in], context)
+ # Procesamos albarán de entrada
+ self.picking_processing(cr, uid, [new_picking_in],
+ date_cur, context)
+ if new_picking_out:
+ # Confirmamos albarán de salida
+ wf_service.trg_validate(uid, 'stock.picking',
+ new_picking_out, 'button_confirm',
+ cr)
+ pick_obj.force_assign(cr, uid, [new_picking_out], context)
+ # Procesamos albarán de entrada
+ self.picking_processing(cr, uid, [new_picking_out],
+ date_cur, context)
+ else:
+ raise orm.except_orm(_('Error !'),
+ _('There are no products to return.'))
+ return self.write(cr, uid, ids,
+ {'state': 'done', 'picking_in_id': new_picking_in,
+ 'picking_out_id': new_picking_out}, context=context)
+
+
+class RefundProduct(osv.osv):
+
+ _name = 'refund.product'
+ _description = "Refund Product"
+ _columns = {
+ 'refund_id': fields.many2one('refund.products', 'Refund Products',
+ select=True, required=True),
+ 'refund_product_id': fields.many2one('product.product',
+ 'Refund Product', select=True,
+ required=True),
+ 'refund_prodlot_id': fields.many2one('stock.production.lot',
+ 'Refund Product Lot', select=True,
+ required=True),
+ 'product_id': fields.many2one('product.product',
+ 'Substitution Product', select=True,
+ required=True),
+ 'prodlot_id': fields.many2one('stock.production.lot',
+ 'Substitution Product Lot', select=True,
+ required=True),
+ 'location_id': fields.many2one('stock.location', 'Source Location',
+ select=True, store=True, required=True),
+ 'location_dest_id': fields.many2one('stock.location',
+ 'Destination Location',
+ required=True),
+ }
+
+ def onchange_refund_product(self, cr, uid, ids, product_id=False,
+ prodlot_id=False):
+ if not product_id or not prodlot_id:
+ return {'value': {'location_id': False, 'location_dest_id': False}}
+ stock_warehouse_obj = self.pool['stock.warehouse']
+ prodlot_obj = self.pool['stock.production.lot']
+ # Comprobamos que hay al menos un almacen definido
+ stock_warehouse = None
+ stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
+ for warehouse in stock_warehouse_obj.browse(cr, uid,
+ stock_warehouse_ids,
+ context=context):
+ stock_warehouse = warehouse
+ break
+ if not stock_warehouse:
+ raise orm.except_orm(_('Stock Warehouse not defined !'),
+ _('Stock Warehouse not defined.'))
+ # Obtenemos movimiento de salida del producto devuelto
+ prodlot = prodlot_obj.browse(cr, uid, prodlot_id)
+ move = prodlot.move_ids and prodlot.move_ids[0] or None
+ for m in prodlot.move_ids:
+ if m.location_id.id == (stock_warehouse.lot_stock_id.id
+ and m.picking_id):
+ move = m
+ break
+ val = {
+ 'location_id': (move and move.location_dest_id and
+ move.location_dest_id.id or False),
+ 'location_dest_id': stock_warehouse.lot_stock_id.id,
+ }
+ return {'value': val}
=== added directory 'dos_refund_products/views'
=== renamed file 'dos_refund_products/refund_products_view.xml' => 'dos_refund_products/views/refund_products_view.xml'
=== modified file 'dos_refund_products/wizard/__init__.py'
--- dos_refund_products/wizard/__init__.py 2014-06-11 10:23:47 +0000
+++ dos_refund_products/wizard/__init__.py 2014-06-26 13:37:14 +0000
@@ -19,7 +19,7 @@
#
##############################################################################
-import break_pack_product
+from . import break_pack_product
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'dos_refund_products/wizard/break_pack_product.py'
--- dos_refund_products/wizard/break_pack_product.py 2014-06-11 10:23:47 +0000
+++ dos_refund_products/wizard/break_pack_product.py 2014-06-26 13:37:14 +0000
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
#
@@ -15,167 +15,174 @@
# 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/>.
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import datetime
-import ir
-from tools.translate import _
-from osv import osv, fields
-
-
-class break_pack_product(osv.osv_memory):
-
- _name = 'break.pack.product'
-
- _columns = {
- 'pack_product_id': fields.many2one('product.product', 'Pack Product', select=True, required=True),
- 'pack_production_lot_id': fields.many2one('stock.production.lot', 'Production Lot', required=True),
- 'sim_product_id': fields.many2one('product.product', 'SIM Product', select=True),
- 'sim_production_lot_id': fields.many2one('stock.production.lot', 'ICC', select=True),
- 'link_product_id': fields.many2one('product.product', 'Link Product', select=True),
- 'link_production_lot_id': fields.many2one('stock.production.lot', 'IMEI', select=True),
- 'state': fields.selection( ( ('draft','Draft'), ('done','Done'), ) ),
- }
-
- _defaults = {
- 'state': lambda *a: 'draft',
- }
-
-
- def break_pack(self, cr, uid, ids, context=None):
-
- stock_warehouse_obj = self.pool.get('stock.warehouse')
- sale_obj = self.pool.get('sale.order')
- stock_picking_obj = self.pool.get('stock.picking')
- stock_move_obj = self.pool.get('stock.move')
- bom_obj = self.pool.get('mrp.bom')
- product_obj = self.pool.get('product.product')
-
- user = self.pool.get('res.users').browse(cr, uid, uid)
- company_id = user.company_id
-
- # Comprobamos que hay al menos un almacen definido
- stock_warehouse = None
- stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
-
- for warehouse in stock_warehouse_obj.browse(cr, uid, stock_warehouse_ids, context):
- stock_warehouse = warehouse
- break
-
- if not stock_warehouse:
- raise osv.except_osv(_('Stock Warehouse not defined !'), _('Stock Warehouse not defined.'))
-
-
- # Comenzamos con la rotura del pack
- for data in self.browse(cr, uid, ids, context=context):
-
- pack_product_id = data.pack_product_id
- pack_production_lot_id = data.pack_production_lot_id
-
- sim_product_id = None
- sim_production_lot_id = None
- link_product_id = None
- link_production_lot_id = None
-
-
- #Si el producto tiene como metodo suministro producir (Pack)
- #Creamos lineas con los materiales que lo componen
- if pack_product_id and pack_product_id.supply_method == 'produce':
- delete = False
-
- bom_id = bom_obj._bom_find(cr, uid, pack_product_id.id, pack_product_id.uom_id and pack_product_id.uom_id.id, [])
-
- if bom_id:
- bom_point = bom_obj.browse(cr, uid, bom_id, context={})
-
- if bom_point.bom_lines:
- #Creamos albarán interno para traspasar los materiales
- #de la ubicacion de produccion a la ubicacion de stock
- vals = {
- 'origin': 'BREAK_PACK',
- 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'move_type': 'direct',
- 'invoice_state': 'none',
- 'state': 'draft',
- 'auto_picking': False,
- 'type': 'internal',
- }
- stock_picking_id = stock_picking_obj.create(cr, uid, vals)
-
- #Recorremos materiales
- for bom_line in bom_point.bom_lines:
- prodlot_id = sale_obj._get_bom_product_lot(cr, uid, stock_warehouse, pack_production_lot_id.id, bom_line.product_id.id)
- location_id = sale_obj._get_bom_stock_location_dest(cr, uid, stock_warehouse, pack_production_lot_id.id, bom_line.product_id.id)
-
- #Si es SIM
- if product_obj._is_sim(bom_line.product_id.categ_id):
- sim_product_id = bom_line.product_id.id
- sim_production_lot_id = prodlot_id
-
- #Si es Enlace
- elif product_obj._is_link(bom_line.product_id.categ_id):
- link_product_id = bom_line.product_id.id
- link_production_lot_id = prodlot_id
-
-
- #Creamos nueva linea de albarán interno
- vals = {
- 'picking_id': stock_picking_id,
- 'product_id': bom_line.product_id.id,
- 'name': '[' + (bom_line.product_id.default_code or '') + '] ' + (bom_line.product_id.name or ''),
- 'prodlot_id': prodlot_id,
- 'product_qty': 1,
- 'product_uos_qty': 1,
- 'product_uom': bom_line.product_id.uom_id and bom_line.product_id.uom_id.id or False,
- 'location_id': location_id,
- 'location_dest_id': stock_warehouse.lot_stock_id.id,
- 'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'auto_validate': False,
- 'priority': '1',
- 'state': 'done',
- }
-
- stock_move_id = stock_move_obj.create(cr, uid, vals)
-
- delete = True
-
- if delete:
- #Creamos linea de salida de pack en albarán interno
- vals = {
- 'picking_id': stock_picking_id,
- 'product_id': pack_product_id.id,
- 'name': '[' + (pack_product_id.default_code or '') + '] ' + (pack_product_id.name or ''),
- 'prodlot_id': pack_production_lot_id.id,
- 'product_qty': 1,
- 'product_uos_qty': 1,
- 'product_uom': pack_product_id.uom_id and pack_product_id.uom_id.id or False,
- 'location_id': stock_warehouse.lot_stock_id.id,
- 'location_dest_id': stock_warehouse.lot_broken_id.id,
- 'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'auto_validate': False,
- 'priority': '1',
- 'state': 'done',
- }
-
- stock_move_id = stock_move_obj.create(cr, uid, vals)
-
- #Validamos albaran interno
- stock_picking_obj.write(cr, uid, [stock_picking_id], {'state': 'done'})
-
-
- return self.write(cr, uid, ids, {'state':'done',
- 'sim_product_id':sim_product_id,
- 'sim_production_lot_id': sim_production_lot_id,
- 'link_product_id':link_product_id,
- 'link_production_lot_id': link_production_lot_id,
- }, context=context)
-
-break_pack_product()
-
+from openerp.addons.base import ir
+from openerp.tools.translate import _
+from openerp.osv import osv, fields
+
+
+class BreakPackProduct(orm.TransientModel):
+ _name = 'break.pack.product'
+ _columns = {
+ 'pack_product_id': fields.many2one('product.product', 'Pack Product',
+ select=True, required=True),
+ 'pack_production_lot_id':
+ fields.many2one('stock.production.lot', 'Production Lot',
+ required=True),
+ 'sim_product_id': fields.many2one('product.product', 'SIM Product',
+ select=True),
+ 'sim_production_lot_id': fields.many2one('stock.production.lot', 'ICC',
+ select=True),
+ 'link_product_id': fields.many2one('product.product', 'Link Product',
+ select=True),
+ 'link_production_lot_id': fields.many2one('stock.production.lot',
+ 'IMEI', select=True),
+ 'state': fields.selection((('draft', 'Draft'), ('done', 'Done'))),
+ }
+ _defaults = {
+ 'state': lambda *a: 'draft',
+ }
+
+ def break_pack(self, cr, uid, ids, context=None):
+ stock_warehouse_obj = self.pool['stock.warehouse']
+ sale_obj = self.pool['sale.order']
+ stock_picking_obj = self.pool['stock.picking']
+ stock_move_obj = self.pool['stock.move']
+ bom_obj = self.pool['mrp.bom']
+ product_obj = self.pool['product.product']
+ user = self.pool['res.users'].browse(cr, uid, uid, context=context)
+ company_id = user.company_id
+ # Comprobamos que hay al menos un almacen definido
+ stock_warehouse = None
+ stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [],
+ context=context)
+ for warehouse in stock_warehouse_obj.browse(
+ cr, uid, stock_warehouse_ids, context):
+ stock_warehouse = warehouse
+ break
+ if not stock_warehouse:
+ raise orm.except_orm(_('Stock Warehouse not defined !'),
+ _('Stock Warehouse not defined.'))
+ # Comenzamos con la rotura del pack
+ for data in self.browse(cr, uid, ids, context=context):
+ pack_product_id = data.pack_product_id
+ pack_production_lot_id = data.pack_production_lot_id
+ sim_product_id = None
+ sim_production_lot_id = None
+ link_product_id = None
+ link_production_lot_id = None
+ # Si el producto tiene como metodo suministro producir (Pack)
+ # Creamos lineas con los materiales que lo componen
+ if pack_product_id and pack_product_id.supply_method == 'produce':
+ delete = False
+ bom_id = bom_obj._bom_find(cr, uid, pack_product_id.id,
+ (pack_product_id.uom_id and
+ pack_product_id.uom_id.id), [])
+ if bom_id:
+ bom_point = bom_obj.browse(cr, uid, bom_id, context={})
+ if bom_point.bom_lines:
+ # Creamos albarán interno para traspasar los materiales
+ # de la ubicacion de produccion a la ubicacion de stock
+ vals = {
+ 'origin': 'BREAK_PACK',
+ 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'move_type': 'direct',
+ 'invoice_state': 'none',
+ 'state': 'draft',
+ 'auto_picking': False,
+ 'type': 'internal',
+ }
+ stock_picking_id = stock_picking_obj.create(
+ cr, uid, vals, context=context)
+ # Recorremos materiales
+ for bom_line in bom_point.bom_lines:
+ prodlot_id = sale_obj._get_bom_product_lot(
+ cr, uid, stock_warehouse,
+ pack_production_lot_id.id,
+ bom_line.product_id.id)
+ location_id = (
+ sale_obj._get_bom_stock_location_dest(
+ cr, uid, stock_warehouse,
+ pack_production_lot_id.id,
+ bom_line.product_id.id))
+ # Si es SIM
+ if product_obj._is_sim(
+ bom_line.product_id.categ_id):
+ sim_product_id = bom_line.product_id.id
+ sim_production_lot_id = prodlot_id
+ # Si es Enlace
+ elif product_obj._is_link(
+ bom_line.product_id.categ_id):
+ link_product_id = bom_line.product_id.id
+ link_production_lot_id = prodlot_id
+ # Creamos nueva linea de albarán interno
+ vals = {
+ 'picking_id': stock_picking_id,
+ 'product_id': bom_line.product_id.id,
+ 'name': (
+ '[%s] %s' %
+ ((bom_line.product_id.default_code or ''),
+ (bom_line.product_id.name or ''))),
+ 'prodlot_id': prodlot_id,
+ 'product_qty': 1,
+ 'product_uos_qty': 1,
+ 'product_uom': (
+ bom_line.product_id.uom_id and
+ bom_line.product_id.uom_id.id
+ or False),
+ 'location_id': location_id,
+ 'location_dest_id':
+ stock_warehouse.lot_stock_id.id,
+ 'date_expected':
+ time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'date':
+ time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'auto_validate': False,
+ 'priority': '1',
+ 'state': 'done',
+ }
+ stock_move_id = stock_move_obj.create(
+ cr, uid, vals, context=context)
+ delete = True
+ if delete:
+ # Creamos linea de salida de pack en albarán interno
+ vals = {
+ 'picking_id': stock_picking_id,
+ 'product_id': pack_product_id.id,
+ 'name': '[%s] %s' % ((pack_product_id.default_code
+ or ''), (pack_product_id.name
+ or '')),
+ 'prodlot_id': pack_production_lot_id.id,
+ 'product_qty': 1,
+ 'product_uos_qty': 1,
+ 'product_uom': (pack_product_id.uom_id and
+ pack_product_id.uom_id.id or False),
+ 'location_id': stock_warehouse.lot_stock_id.id,
+ 'location_dest_id':
+ stock_warehouse.lot_broken_id.id,
+ 'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'auto_validate': False,
+ 'priority': '1',
+ 'state': 'done',
+ }
+ stock_move_id = stock_move_obj.create(cr, uid, vals,
+ context=context)
+ # Validamos albaran interno
+ stock_picking_obj.write(cr, uid, [stock_picking_id],
+ {'state': 'done'}, context=context)
+ return self.write(
+ cr, uid, ids, {
+ 'state': 'done',
+ 'sim_product_id': sim_product_id,
+ 'sim_production_lot_id': sim_production_lot_id,
+ 'link_product_id': link_product_id,
+ 'link_production_lot_id': link_production_lot_id,
+ }, context=context)
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
=== modified file 'dos_refund_products/wizard/break_pack_product_view.xml'
--- dos_refund_products/wizard/break_pack_product_view.xml 2014-06-11 10:23:47 +0000
+++ dos_refund_products/wizard/break_pack_product_view.xml 2014-06-26 13:37:14 +0000
@@ -5,7 +5,6 @@
<record id="view_break_pack_product_wizard" model="ir.ui.view">
<field name="name">Break Pack Product</field>
<field name="model">break.pack.product</field>
- <field name="type">form</field>
<field name="arch" type="xml">
<form string="Break Pack Product">
<group col="8">
Follow ups