summaryrefslogtreecommitdiff
path: root/addons/purchase
diff options
context:
space:
mode:
authornch@tinyerp.com <>2010-05-12 12:17:56 +0530
committernch@tinyerp.com <>2010-05-12 12:17:56 +0530
commitf0aa8a0a0c1367161eba7426d9a37d61ba8bd899 (patch)
tree468357a929cf8584e174458c1ead6f19bee58014 /addons/purchase
parentce10539ffb5bd18fa2578689f152c88be6966d89 (diff)
parentbd933e119001332a6eea3255d490a62ccf7fb5fb (diff)
[MERGE]
bzr revid: nch@tinyerp.com-20100512064756-778rth7jwjwhcjsz
Diffstat (limited to 'addons/purchase')
-rw-r--r--addons/purchase/__init__.py1
-rw-r--r--addons/purchase/__openerp__.py3
-rw-r--r--addons/purchase/company.py36
-rw-r--r--addons/purchase/company_view.xml18
-rw-r--r--addons/purchase/purchase.py82
-rw-r--r--addons/purchase/purchase_view.xml17
-rw-r--r--addons/purchase/purchase_workflow.xml27
7 files changed, 182 insertions, 2 deletions
diff --git a/addons/purchase/__init__.py b/addons/purchase/__init__.py
index 41c673c0104..301e32ebca9 100644
--- a/addons/purchase/__init__.py
+++ b/addons/purchase/__init__.py
@@ -25,6 +25,7 @@ import stock
import wizard
import report
import stock
+import company
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py
index 6687b330b2c..909b785fe72 100644
--- a/addons/purchase/__openerp__.py
+++ b/addons/purchase/__openerp__.py
@@ -31,7 +31,7 @@
""",
'author': 'Tiny',
'website': 'http://www.openerp.com',
- 'depends': ['base', 'account', 'stock', 'process'],
+ 'depends': ['base', 'account', 'stock', 'process', 'mrp_procurement'],
'init_xml': [],
'update_xml': [
@@ -39,6 +39,7 @@
'security/ir.model.access.csv',
'purchase_workflow.xml',
'purchase_sequence.xml',
+ 'company_view.xml',
'purchase_data.xml',
'wizard/purchase_order_group_view.xml',
'wizard/purchase_installer.xml',
diff --git a/addons/purchase/company.py b/addons/purchase/company.py
new file mode 100644
index 00000000000..2a01605782c
--- /dev/null
+++ b/addons/purchase/company.py
@@ -0,0 +1,36 @@
+# -*- 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 osv import osv,fields
+
+class company(osv.osv):
+ _inherit = 'res.company'
+ _columns = {
+ 'po_lead': fields.float('Purchase Lead Time', required=True,
+ help="This is the leads/security time for each purchase order."),
+ }
+ _defaults = {
+ 'po_lead': lambda *a: 1.0,
+ }
+company()
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/purchase/company_view.xml b/addons/purchase/company_view.xml
new file mode 100644
index 00000000000..d7707fe32c7
--- /dev/null
+++ b/addons/purchase/company_view.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" ?>
+<openerp>
+ <data>
+
+ <record id="mrp_company" model="ir.ui.view">
+ <field name="name">res.company.mrp.config</field>
+ <field name="model">res.company</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="base.view_company_form"/>
+ <field name="arch" type="xml">
+ <page string="Configuration" position="inside">
+ <field name="po_lead"/>
+ </page>
+ </field>
+ </record>
+
+ </data>
+</openerp>
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index 2bcc62c06ac..a7d69159873 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -19,6 +19,7 @@
#
##############################################################################
+from mx import DateTime
from osv import fields
from osv import osv
import time
@@ -692,5 +693,86 @@ class purchase_order_line(osv.osv):
return True
purchase_order_line()
+class mrp_procurement(osv.osv):
+ _inherit = 'mrp.procurement'
+ _columns = {
+ 'purchase_id': fields.many2one('purchase.order', 'Purchase Order'),
+ }
+
+ def action_po_assign(self, cr, uid, ids, context={}):
+ """ This is action which call from workflow to assign purchase order to procurements
+ @return: True
+ """
+ res = self.make_po(cr, uid, ids, context=context)
+ res = res.values()
+ return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
+
+ def make_po(self, cr, uid, ids, context={}):
+ """ Make purchase order from procurement
+ @return: New created Purchase Orders procurement wise
+ """
+ res = {}
+ company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
+ partner_obj = self.pool.get('res.partner')
+ uom_obj = self.pool.get('product.uom')
+ pricelist_obj = self.pool.get('product.pricelist')
+ prod_obj = self.pool.get('product.product')
+ acc_pos_obj = self.pool.get('account.fiscal.position')
+ po_obj = self.pool.get('purchase.order')
+ for procurement in self.browse(cr, uid, ids):
+ res_id = procurement.move_id.id
+ partner = procurement.product_id.seller_ids[0].name
+ partner_id = partner.id
+ address_id = partner_obj.address_get(cr, uid, [partner_id], ['delivery'])['delivery']
+ pricelist_id = partner.property_product_pricelist_purchase.id
+
+ uom_id = procurement.product_id.uom_po_id.id
+
+ qty = uom_obj._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, uom_id)
+ if procurement.product_id.seller_ids[0].qty:
+ qty = max(qty,procurement.product_id.seller_ids[0].qty)
+
+ price = pricelist_obj.price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, False, {'uom': uom_id})[pricelist_id]
+
+ newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S')
+ newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead)
+ newdate = newdate - procurement.product_id.seller_ids[0].delay
+
+ #Passing partner_id to context for purchase order line integrity of Line name
+ context.update({'lang': partner.lang, 'partner_id': partner_id})
+
+ product = prod_obj.browse(cr, uid, procurement.product_id.id, context=context)
+
+ line = {
+ 'name': product.partner_ref,
+ 'product_qty': qty,
+ 'product_id': procurement.product_id.id,
+ 'product_uom': uom_id,
+ 'price_unit': price,
+ 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
+ 'move_dest_id': res_id,
+ 'notes': product.description_purchase,
+ }
+
+ taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
+ taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
+ line.update({
+ 'taxes_id': [(6,0,taxes)]
+ })
+ purchase_id = po_obj.create(cr, uid, {
+ 'origin': procurement.origin,
+ 'partner_id': partner_id,
+ 'partner_address_id': address_id,
+ 'location_id': procurement.location_id.id,
+ 'pricelist_id': pricelist_id,
+ 'order_line': [(0,0,line)],
+ 'company_id': procurement.company_id.id,
+ 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False
+ })
+ res[procurement.id] = purchase_id
+ self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id})
+ return res
+mrp_procurement()
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml
index 839dc4306fa..555d1fb085c 100644
--- a/addons/purchase/purchase_view.xml
+++ b/addons/purchase/purchase_view.xml
@@ -323,7 +323,22 @@
<field name="act_window_id" ref="purchase_line_form_action2"/>
</record>
<menuitem action="purchase_line_form_action2" id="menu_purchase_line_order_draft" parent="menu_procurement_management_invoice"/>
-
+
+ <!--
+ Procurements
+ -->
+
+ <record id="view_procurement_form_inherit" model="ir.ui.view">
+ <field name="name">mrp.procurement.form.inherit</field>
+ <field name="model">mrp.procurement</field>
+ <field name="inherit_id" ref="mrp_procurement.mrp_procurement_form_view"/>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <xpath expr="/form/notebook/page/field[@name='close_move']" position="before">
+ <field name="purchase_id"/>
+ </xpath>
+ </field>
+ </record>
</data>
</openerp>
diff --git a/addons/purchase/purchase_workflow.xml b/addons/purchase/purchase_workflow.xml
index 26f83d5a554..d7684be1875 100644
--- a/addons/purchase/purchase_workflow.xml
+++ b/addons/purchase/purchase_workflow.xml
@@ -177,6 +177,33 @@
<field name="act_from" ref="act_invoice_end"/>
<field name="act_to" ref="act_done"/>
</record>
+
+ <!-- Procurement -->
+ <record id="act_buy" model="workflow.activity">
+ <field name="wkf_id" ref="mrp_procurement.wkf_procurement"/>
+ <field name="name">buy</field>
+ <field name="kind">subflow</field>
+ <field name="subflow_id" search="[('osv','=','purchase.order')]"/>
+ <field name="action">action_po_assign()</field>
+ </record>
+
+ <record id="trans_confirm_mto_buy" model="workflow.transition">
+ <field name="act_from" ref="mrp_procurement.act_confirm_mto"/>
+ <field name="act_to" ref="act_buy"/>
+ <field name="condition">check_buy()</field>
+ </record>
+
+ <record id="trans_buy_make_done" model="workflow.transition">
+ <field name="act_from" ref="act_buy"/>
+ <field name="act_to" ref="mrp_procurement.act_make_done"/>
+ <field name="signal">subflow.delivery_done</field>
+ </record>
+
+ <record id="trans_buy_cancel" model="workflow.transition">
+ <field name="act_from" ref="act_buy"/>
+ <field name="act_to" ref="mrp_procurement.act_cancel"/>
+ <field name="signal">subflow.cancel</field>
+ </record>
</data>
</openerp>