[IMP] Adapt average yml and push flow yml, put stock.py from sale_stock in stock_account
authorJosse Colpaert <jco@openerp.com>
Wed, 28 Aug 2013 15:32:10 +0000 (17:32 +0200)
committerJosse Colpaert <jco@openerp.com>
Wed, 28 Aug 2013 15:32:10 +0000 (17:32 +0200)
bzr revid: jco@openerp.com-20130828153210-cn97txe5046vo4nk

addons/purchase/test/average_price.yml
addons/sale_stock/__init__.py
addons/sale_stock/sale_stock_view.xml
addons/sale_stock/stock.py [deleted file]
addons/stock_account/__init__.py
addons/stock_account/stock_account.py
addons/stock_account/stock_account_view.xml
addons/stock_location/test/stock_location_push_flow.yml

index 0fa2dfb..79bae83 100644 (file)
 - 
   Process the reception of purchase order 1
 -
-  !python {model: stock.partial.picking}: |
+  !python {model: stock.picking}: |
     pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_average1")).picking_ids
-    partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
-    self.do_partial(cr, uid, [partial_id])
+    self.do_partial(cr, uid, [pick_ids[0].id])
 - 
   Check the standard price of the product (average icecream). 
 - 
 - 
   Process the reception of purchase order 2
 - 
-  !python {model: stock.partial.picking}: |
+  !python {model: stock.picking}: |
     pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_average2")).picking_ids
-    partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
-    self.do_partial(cr, uid, [partial_id])
+    self.do_partial(cr, uid, [pick_ids[0].id])
 - 
   Check the standard price
 - 
@@ -82,7 +80,7 @@
   Create picking to send some goods
 - 
   !record {model: stock.picking, id: outgoing_average_shipment}:
-    type: out
+    picking_type_id: stock.picking_type_out
 - 
   Create move for picking
 - 
     product_id: product_average_icecream
     product_uom: product.product_uom_kgm
     product_qty: 20.0
-    type: out
 - 
-  I assign this outgoing shipment 
+  I assign this outgoing shipment and process the delivery
 - 
   !python {model: stock.picking}: |
     self.action_assign(cr, uid, [ref("outgoing_average_shipment")])
-- 
-  Process the delivery of the outgoing shipment
-- 
-  !python {model: stock.partial.picking}: |
-    partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [ref("outgoing_average_shipment")], 'default_type':'out'})
-    self.do_partial(cr, uid, [partial_id])
+    self.do_partial(cr, uid, [ref("outgoing_average_shipment")])
 - 
   Check the standard price (60 * 10 + 30 * 80) / 40 = 75.0 did not change
 - 
 - 
   Process the reception of purchase order 3 in grams
 - 
-  !python {model: stock.partial.picking}: |
+  !python {model: stock.picking}: |
     pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_average3")).picking_ids
-    partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
-    self.do_partial(cr, uid, [partial_id])
+    self.do_partial(cr, uid, [pick_ids[0].id])
 - 
   Check price is (75.0*20 + 500) / 20.5 = 97.56097561
 - 
index f521deb..72b3d56 100644 (file)
@@ -20,7 +20,6 @@
 ##############################################################################
 
 import sale_stock
-import stock
 import report
 import company
 import res_config
index 03731bd..9e14ce4 100644 (file)
             groups="sale.group_delivery_invoice_address"
             />
 
-        <record id="view_picking_inherit_form2" model="ir.ui.view">
-            <field name="name">stock.picking.form.inherit</field>
-            <field name="model">stock.picking</field>
-            <field name="inherit_id" ref="stock.view_picking_form"/>
-            <field name="arch" type="xml">
-                <xpath expr="//button[@name='do_prepare_partial']" position="after">
-                    <button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" attrs="{'invisible': ['|',('state','&lt;&gt;','done'),('invoice_state','&lt;&gt;','2binvoiced')]}" type="action" class="oe_highlight" groups="base.group_user"/>
-                    <button name="%(action_stock_invoice_onshipping)d" string="Refund Invoice" attrs="{'invisible': ['|',('state','&lt;&gt;','done'),('invoice_state','&lt;&gt;','invoiced')]}" type="action" class="oe_highlight" groups="base.group_user" context="{'inv_type': 'out_refund'}"/>
-                </xpath>
-                <xpath expr="//field[@name='move_type']" position="after">
-                    <field name="invoice_state" groups="account.group_account_invoice"/>
-                </xpath>
 
-            </field>
-        </record>
 
         <record id="view_picking_internal_search_inherit" model="ir.ui.view">
             <field name="name">stock.picking.search.inherit</field>
diff --git a/addons/sale_stock/stock.py b/addons/sale_stock/stock.py
deleted file mode 100644 (file)
index e404ab3..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-#    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 fields, osv
-from openerp.tools.translate import _
-
-
-class stock_picking(osv.osv):
-    _inherit = 'stock.picking'
-    def __get_invoice_state(self, cr, uid, ids, name, arg, context=None):
-        result = {}
-        for pick in self.browse(cr, uid, ids, context=context):
-            result[pick.id] = 'none'
-            for move in pick.move_lines:
-                if move.procurement_id:
-                    if move.procurement_id.invoice_state=='invoiced':
-                        result[pick.id] = 'invoiced'
-                    elif move.procurement_id.invoice_state=='2binvoiced':
-                        result[pick.id] = '2binvoiced'
-                        break
-        return result
-
-    def __get_picking_procurement(self, cr, uid, ids, context={}):
-        result = {}
-        for proc in self.pool.get('procurement.order').browse(cr, uid, ids, context=context):
-            for move in proc.move_ids:
-                if move.picking_id:
-                    result[move.picking_id.id] = True
-        return result.keys()
-
-    def __get_picking_move(self, cr, uid, ids, context={}):
-        res = []
-        for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context):
-            if move.picking_id: 
-                res.append(move.picking_id.id)
-        return res
-
-    _columns = {
-        'invoice_state': fields.function(__get_invoice_state, type='selection', selection=[
-            ("invoiced", "Invoiced"),
-            ("2binvoiced", "To Be Invoiced"),
-            ("none", "Not Applicable")
-          ], string="Invoice Control", required=True, 
-        store={
-          'procurement.order': (__get_picking_procurement, ['invoice_state'], 10),
-          'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10),
-          'stock.move': (__get_picking_move, ['picking_id'], 10),
-        },
-        ),
-    }
-    _defaults = {
-        'invoice_state': lambda *args, **argv: 'none'
-    }
-
-    def action_invoice_create(self, cr, uid, ids, journal_id=False, group=False, type='out_invoice', context=None):
-        """ Creates invoice based on the invoice state selected for picking.
-        @param journal_id: Id of journal
-        @param group: Whether to create a group invoice or not
-        @param type: Type invoice to be created
-        @return: Ids of created invoices for the pickings
-        """
-        context = context or {}
-        todo = {}
-        for picking in self.browse(cr, uid, ids, context=context):
-            key = group and picking.id or True
-            for move in picking.move_lines:
-                if move.procurement_id and (move.procurement_id.invoice_state=='2binvoiced'):
-                    if (move.state <> 'cancel') and not move.scrapped:
-                        todo.setdefault(key, [])
-                        todo[key].append(move)
-        invoices = []
-        for moves in todo.values():
-            invoices = self.__invoice_create_line(cr, uid, moves, journal_id, type, context=context)
-        return invoices
-
-    def __invoice_create_line(self, cr, uid, moves, journal_id=False, inv_type='out_invoice', context=None):
-        invoice_obj = self.pool.get('account.invoice')
-        invoices = {}
-        for move in moves:
-            sale_line = move.procurement_id.sale_line_id
-            sale = sale_line.order_id
-            partner = sale.partner_invoice_id
-
-            currency_id = sale.pricelist_id.currency_id.id
-            key = (partner.id, currency_id, sale.company_id.id, sale.user_id and sale.user_id.id or False)
-
-            if key not in invoices:
-                # Get account and payment terms
-                if inv_type in ('out_invoice', 'out_refund'):
-                    account_id = partner.property_account_receivable.id
-                    payment_term = partner.property_payment_term.id or False
-                else:
-                    account_id = partner.property_account_payable.id
-                    payment_term = partner.property_supplier_payment_term.id or False
-
-                invoice_id = invoice_obj.create(cr, uid, {
-                    'origin': sale.name,
-                    'date_invoice': context.get('date_inv', False),
-                    'user_id': sale.user_id and sale.user_id.id or False,
-                    'partner_id': partner.id,
-                    'account_id': account_id,
-                    'payment_term': payment_term,
-                    'type': inv_type,
-                    'fiscal_position': partner.property_account_position.id,
-                    'company_id': sale.company_id.id,
-                    'currency_id': sale.pricelist_id.currency_id.id,
-                    'journal_id': journal_id,
-                }, context=context)
-                invoices[key] = invoice_id
-
-            # Get account_id
-            if inv_type in ('out_invoice', 'out_refund'):
-                account_id = move.product_id.property_account_income.id
-                if not account_id:
-                    account_id = move.product_id.categ_id.property_account_income_categ.id
-            else:
-                account_id = move.product_id.property_account_expense.id
-                if not account_id:
-                    account_id = move.product_id.categ_id.property_account_expense_categ.id
-            fp_obj = self.pool.get('account.fiscal.position')
-            fiscal_position = partner.property_account_position
-            account_id = fp_obj.map_account(cr, uid, fiscal_position, account_id)
-
-            # set UoS if it's a sale and the picking doesn't have one
-            if move.product_uos:
-                uos_id = move.product_uos.id
-                quantity = move.product_uos_qty
-            else:
-                uos_id = move.product_uom.id
-                quantity = move.product_uom_qty
-
-            invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, {
-                'name': move.name,
-                'origin': move.picking_id and move.picking_id.origin or False,
-                'invoice_id': invoices[key],
-                'account_id': account_id,
-                'product_id': move.product_id.id,
-                'uos_id': uos_id,
-                'quantity': quantity,
-                'price_unit': sale_line.price_unit,
-                'discount': sale_line.discount,
-                'invoice_line_tax_id': [(6, 0, [x.id for x in sale_line.tax_id])],
-                'account_analytic_id': sale.project_id and sale.project_id.id or False,
-            }, context=context)
-
-            self.pool.get('sale.order.line').write(cr, uid, [sale_line.id], {
-                'invoice_lines': [(4, invoice_line_id)]
-            }, context=context)
-            self.pool.get('sale.order').write(cr, uid, [sale.id], {
-                'invoice_ids': [(4, invoices[key])],
-            })
-
-            self.pool.get('procurement.order').write(cr, uid, [move.procurement_id.id], {
-                'invoice_state': 'invoiced',
-            }, context=context)
-
-        invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
-        return invoices.values()
index 3bab8f5..d74ac75 100644 (file)
@@ -21,5 +21,6 @@
 
 import product
 import stock_account
+import stock
 import wizard
 
index 2dc3d80..f9e62fa 100644 (file)
@@ -34,6 +34,12 @@ import openerp.addons.decimal_precision as dp
 import logging
 _logger = logging.getLogger(__name__)
 
+#----------------------------------------------------------
+# Invoice state
+#----------------------------------------------------------
+
+
+
 
 #----------------------------------------------------------
 # Stock Location
index cf9aaeb..a7e6bc8 100644 (file)
             </field>
         </record>
 
+
+        <record id="view_picking_inherit_form2" model="ir.ui.view">
+            <field name="name">stock.picking.form.inherit</field>
+            <field name="model">stock.picking</field>
+            <field name="inherit_id" ref="stock.view_picking_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//button[@name='do_prepare_partial']" position="after">
+                    <button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" attrs="{'invisible': ['|',('state','&lt;&gt;','done'),('invoice_state','&lt;&gt;','2binvoiced')]}" type="action" class="oe_highlight" groups="base.group_user"/>
+                    <button name="%(action_stock_invoice_onshipping)d" string="Refund Invoice" attrs="{'invisible': ['|',('state','&lt;&gt;','done'),('invoice_state','&lt;&gt;','invoiced')]}" type="action" class="oe_highlight" groups="base.group_user" context="{'inv_type': 'out_refund'}"/>
+                </xpath>
+                <xpath expr="//field[@name='move_type']" position="after">
+                    <field name="invoice_state" groups="account.group_account_invoice"/>
+                </xpath>
+
+            </field>
+        </record>
     </data>
 </openerp>
index 3a6f0a1..0d9c71a 100644 (file)
         - invoice_state: none
           location_dest_id: stock_location.stock_location_qualitytest0
           location_from_id: stock.stock_location_stock
+          picking_type_id: stock.picking_type_internal
         - invoice_state: none
           location_dest_id: stock.stock_location_components
           location_from_id: stock_location.stock_location_qualitytest0
+          picking_type_id: stock.picking_type_internal
 -
   !record {model: product.product, id: product_product_hpcdwriters01}:
     list_price: 1000.0