← Back to team overview

savoirfairelinux-openerp team mailing list archive

lp:~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery-stock_move_autolot into lp:~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery

 

Sandy Carter (http://www.savoirfairelinux.com) has proposed merging lp:~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery-stock_move_autolot into lp:~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery.

Requested reviews:
  Alexandre Boily (alexandre-boily)

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery-stock_move_autolot/+merge/191884

Fabrication d'un nouveau produit + récupération des informations des produits consommés + création d'un compte analytique pour le produit fabriqué (#31066)

Petite modif à purchase_lot_tracking dans les cas d'erreurs d'index quand un compte analytic n'a pas de purchase order line (produit de manufactoring)
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery-stock_move_autolot/+merge/191884
Your team Savoir-faire Linux' OpenERP is subscribed to branch lp:~savoirfairelinux-openerp/purchase-wkfl/pallet-delivery.
=== modified file 'purchase_lot_tracking/account.py'
--- purchase_lot_tracking/account.py	2013-10-18 17:23:17 +0000
+++ purchase_lot_tracking/account.py	2013-10-18 20:51:24 +0000
@@ -63,17 +63,18 @@
 
     def _estimated_tcu(self, cr, uid, ids, name, arg, context=None):
         res = {}
-
+        po_line_pool = self.pool.get('purchase.order.line')
         for line in self.browse(cr, uid, ids):
             if line.code.startswith('LOT'):
-                po_line_pool = self.pool.get('purchase.order.line')
-                po_line_id = po_line_pool.search(cr, uid, [('account_analytic_id', '=', line.id)])[0]
-                po_line = po_line_pool.browse(cr, uid, po_line_id, context)
-
-                res[line.id] = po_line.landed_costs / po_line.product_qty
+                po_line_ids = po_line_pool.search(cr, uid, [('account_analytic_id', '=', line.id)])
+                if po_line_ids:
+                    po_line_id = po_line_ids[0]
+                    po_line = po_line_pool.browse(cr, uid, po_line_id, context)
+                    res[line.id] = po_line.landed_costs / po_line.product_qty
+                else:
+                    res[line.id] = 0.0
             else:
                 res[line.id] = 0.0
-
         return res
 
     _columns = {

=== added directory 'stock_move_autolot'
=== added file 'stock_move_autolot/__init__.py'
--- stock_move_autolot/__init__.py	1970-01-01 00:00:00 +0000
+++ stock_move_autolot/__init__.py	2013-10-18 20:51:24 +0000
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    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/>.
+#
+
+import stock
+import account
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'stock_move_autolot/__openerp__.py'
--- stock_move_autolot/__openerp__.py	1970-01-01 00:00:00 +0000
+++ stock_move_autolot/__openerp__.py	2013-10-18 20:51:24 +0000
@@ -0,0 +1,39 @@
+# -*- encoding: utf-8 -*-
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    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/>.
+#
+
+{
+    'name': 'Auto-Consume lot',
+    'version': '1.0',
+    'author': 'Savoir-faire Linux',
+    'maintainer': 'Savoir-faire Linux',
+    'website': 'http://www.savoirfairelinux.com',
+    'caterogy': 'Manufacturing',
+    'description': """\
+Auto lot assignment when consuming product.
+""",
+    'depends': ['mrp', 'purchase_lot_tracking'],
+    'data': [],
+    'demo': [],
+    'test': [],
+    'installable': True,
+    'active': False,
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'stock_move_autolot/account.py'
--- stock_move_autolot/account.py	1970-01-01 00:00:00 +0000
+++ stock_move_autolot/account.py	2013-10-18 20:51:24 +0000
@@ -0,0 +1,56 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    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.osv import orm, fields
+
+
+class account_analytic_account(orm.Model):
+    _inherit = 'account.analytic.account'
+
+    def _estimated_tcu(self, cr, uid, ids, name, arg, context=None):
+        # Pools
+        stock_move_pool = self.pool.get('stock.move')
+        po_line_pool = self.pool.get('purchase.order.line')
+
+        def transformed_tcu():
+            """Get parent_po_line and calculate price based on transformation"""
+            parent_po_id = po_line_pool.search(cr, uid, [('order_id', '=', line.purchase_order.id)], context=context)[0]
+            parent_po_line = po_line_pool.browse(cr, uid, parent_po_id, context=context)
+            stock_move_id = stock_move_pool.search(cr, uid, [('prodlot_id.name', '=', line.code)], context=context)[0]
+            stock_move = stock_move_pool.browse(cr, uid, stock_move_id, context=context)
+            # Calculate transformed price
+            return parent_po_line.landed_costs / (parent_po_line.product_qty * stock_move.production_id.bom_id.product_qty)
+
+        # Call super
+        res = super(account_analytic_account, self)._estimated_tcu(cr, uid, ids, name, arg, context)
+        for line in self.browse(cr, uid, ids):
+            if line.code.startswith('LOT') and not po_line_pool.search(cr, uid, [('account_analytic_id', '=', line.id)]):
+                res[line.id] = transformed_tcu()
+
+        return res
+
+    # Overwrite estimated_tcu
+    _columns = {
+        'estimated_tcu': fields.function(_estimated_tcu, string='Estimated Total Cost per Unit', type='float'),
+    }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'stock_move_autolot/stock.py'
--- stock_move_autolot/stock.py	1970-01-01 00:00:00 +0000
+++ stock_move_autolot/stock.py	2013-10-18 20:51:24 +0000
@@ -0,0 +1,86 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    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.osv import orm
+
+
+class stock_move(orm.Model):
+    _inherit = "stock.move"
+
+    def action_consume(self, cr, uid, ids, quantity, location_id=False, context=None):
+        """ Consumed product with specific quatity from specific source location
+        @param cr: the database cursor
+        @param uid: the user id
+        @param ids: ids of stock move object to be consumed
+        @param quantity : specify consume quantity
+        @param location_id : specify source location
+        @param context: context arguments
+        @return: Consumed lines
+        """
+        stock_move_obj = self.browse(cr, uid, ids, context=context)[0]
+        if stock_move_obj and stock_move_obj.location_id and stock_move_obj.location_id.name == 'Production':
+            self.autoassign_newlot(cr, uid, ids, stock_move_obj, context=context)
+        return super(stock_move, self).action_consume(cr, uid, ids, quantity, location_id, context=context)
+
+    def autoassign_newlot(self, cr, uid, ids, stock_move_obj, context=None):
+        """
+        Generate and assign a new stock_production_lot to consumable product.
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: the ID or list of IDs if we want more than one
+        @param stock_move_obj: the browse object of the stock
+        @param context: A standard dictionary
+        @return:
+        """
+        # Pools
+        stock_move_pool = self.pool.get('stock.move')
+        # Get product account
+        consumed_stock_move_id = stock_move_pool.search(cr, uid, [('move_dest_id', '=', stock_move_obj.id)])[0]
+        consumed_stock_move = stock_move_pool.browse(cr, uid, consumed_stock_move_id, context=context)
+        product_account = consumed_stock_move.prodlot_id.account_analytic_id
+        # Generate next Lot name
+        new_lot_name = self.pool.get('ir.sequence').next_by_code(cr, uid, 'ls.lot', context=context)
+        # Create new analytic account
+        vals = {
+            'name': new_lot_name,
+            'code': new_lot_name,
+            'parent_id': stock_move_obj.product_id.id,
+            'state': product_account.state,
+            'type': product_account.type,
+            'company_id': product_account.company_id and product_account.company_id.id,
+            'manager_id': product_account.manager_id and product_account.manager_id.id,
+            'template_id': product_account.template_id and product_account.template_id.id,
+            'purchase_order': product_account.purchase_order and product_account.purchase_order.id,
+        }
+        new_analytic_account_id = self.pool.get('account.analytic.account').create(cr, uid, vals)
+        # Create new lot id
+        vals = {
+            'name': new_lot_name,
+            'account_analytic_id': new_analytic_account_id,
+            'product_id': stock_move_obj.product_id and stock_move_obj.product_id.id,
+        }
+        new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, vals, context=context)
+        # Assign new lot number
+        self.write(cr, uid, stock_move_obj.id, {'prodlot_id': new_lot_id})
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:


Follow ups