deisy 6 năm trước cách đây
commit
cb2c41f94a
5 tập tin đã thay đổi với 135 bổ sung0 xóa
  1. 4 0
      README.rst
  2. 1 0
      __init__.py
  3. 48 0
      __openerp__.py
  4. 63 0
      purchase.py
  5. 19 0
      views/view.xml

+ 4 - 0
README.rst

@@ -0,0 +1,4 @@
+Purchase Order Cost Price Update
+=====================================
+
+Description: https://apps.odoo.com/apps/modules/8.0/purchase_order_update_prices/

+ 1 - 0
__init__.py

@@ -0,0 +1 @@
+from . import purchase

+ 48 - 0
__openerp__.py

@@ -0,0 +1,48 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    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': 'Purchase Order Cost Price Update',
+    'version': '1.0',
+    'category': 'Purchase',
+    'summary': 'Update product cost price from purchase orders',
+    'description': """
+	After confirming purchase order and validating invoice, automatically updates product cost price with respective purchase order line unit price
+    
+    
+	""",
+    'author': 'Tahir Aduragba',
+    'website': '',
+    'depends': [   
+        'purchase',
+    ],
+    'data': [
+        'views/view.xml'
+    ],
+    'demo': [
+    ],
+    'test': [
+
+    ],
+    'installable': True,
+    'application': False,
+    'auto_install': False,
+    'images': [],
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 63 - 0
purchase.py

@@ -0,0 +1,63 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#    
+#    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 osv, orm
+from openerp import SUPERUSER_ID, workflow, models, fields
+
+
+class purchase_order(orm.Model):
+    _inherit = 'purchase.order'
+    
+    def _update_product_cost_price(self, cr, uid, ids, context=None):
+        
+        purchase_order_line_obj = self.pool.get('purchase.order.line')
+        product_template_obj = self.pool.get('product.template')
+        
+        ## update product cost with unit price of respective po line 
+        current_po = self.browse(cr, uid, ids, context=context)
+        for po in current_po:
+            for po_line in po.order_line:
+                product_tmpl = po_line.product_id.product_tmpl_id
+                update_price = po_line.price_unit
+                ## check if user chose to update cost price & current cost price is same as po line unit cost (update_price)
+                if po_line.update_cost_price and (product_tmpl.standard_price != update_price):
+                    vals = {
+                        'standard_price' : update_price
+                    }
+                    product_template_obj.write(cr,uid,[product_tmpl.id],vals,context=context)
+
+class purchase_order_line(models.Model):
+    _inherit = 'purchase.order.line'
+    
+    update_cost_price = fields.Boolean(string="Update Cost Price?", default= True, help="Select to update cost price of product after confirming invoice")
+     
+class account_invoice(osv.Model):
+    _inherit = 'account.invoice'
+
+    def invoice_validate(self, cr, uid, ids, context=None):
+        res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
+        purchase_order_obj = self.pool.get('purchase.order')
+        # read access on purchase.order object is not required
+        if not purchase_order_obj.check_access_rights(cr, uid, 'read', raise_exception=False):
+            user_id = SUPERUSER_ID
+        else:
+            user_id = uid
+        po_ids = purchase_order_obj.search(cr, user_id, [('invoice_ids', 'in', ids)], context=context)
+        for po_id in po_ids:
+            purchase_order_obj._update_product_cost_price(cr, user_id, [po_id],context=context)
+        return res

+ 19 - 0
views/view.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<openerp>
+<data>
+
+          <!-- Add update product cost price option in purchase order line. -->
+    <record id="view_purchase_update_product_cost_price" model="ir.ui.view">
+        <field name="name">view.purchase.product.prices</field>
+        <field name="model">purchase.order</field>
+        <field name="inherit_id" ref="purchase.purchase_order_form"/>
+        <field name="arch" type="xml">
+            <xpath expr="//tree/field[@name='state']" position="after">
+                <field name="update_cost_price"/>
+            </xpath>
+        </field>
+    </record>
+
+
+</data>
+</openerp>