[IMP] Improved code for purchase_double_validation
bzr revid: tpa@tinyerp.com-20120305090923-smx09xq1ju7a088s
This commit is contained in:
parent
d4ccb87316
commit
2501d12b39
|
@ -22,7 +22,7 @@
|
|||
from osv import fields, osv
|
||||
|
||||
class product_groups_configuration(osv.osv_memory):
|
||||
_inherit = 'res.config'
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
_columns = {
|
||||
'group_purchase_pricelist_per_supplier':fields.boolean("Pricelist per Supplier",
|
||||
|
|
|
@ -24,14 +24,14 @@ import pooler
|
|||
from tools.translate import _
|
||||
|
||||
class purchase_configuration(osv.osv_memory):
|
||||
_inherit = 'res.config'
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
_columns = {
|
||||
'default_method' : fields.selection(
|
||||
[('manual', 'Based on Purchase Order Lines'),
|
||||
('picking', 'Based on Receptions'),
|
||||
('order', 'Pre-Generate Draft Invoices based on Purchase Orders'),
|
||||
], 'Invoicing Control Method', required=True),
|
||||
], 'Invoicing Control Method', required=True , help="You can set Invoicing Control Method."),
|
||||
'module_purchase_analytic_plans': fields.boolean('Purchase Analytic Plan',
|
||||
help ="""
|
||||
Allows the user to maintain several analysis plans. These let you split
|
||||
|
@ -52,120 +52,16 @@ class purchase_configuration(osv.osv_memory):
|
|||
'module_purchase_double_validation': fields.boolean("Configure Limit amount",
|
||||
help="""This allows you double-validation for purchases exceeding minimum amount.
|
||||
It installs the purchase_double_validation module."""),
|
||||
'purchase_limit': fields.float('Value'),
|
||||
'module_purchase_requisition' : fields.boolean("Track the best price with Purchase Requisition",
|
||||
help="""When a purchase order is created, you now have the opportunity to save the related requisition.
|
||||
This new object will regroup and will allow you to easily keep track and order all your purchase orders.
|
||||
It Installs purchase_requisition module."""),
|
||||
}
|
||||
|
||||
# def get_default_installed_modules(self, cr, uid, ids, context=None):
|
||||
# installed_modules = super(purchase_configuration, self).get_default_installed_modules(cr, uid, ids, context=context)
|
||||
# return installed_modules
|
||||
|
||||
# def get_default_sale_configs(self, cr, uid, ids, context=None):
|
||||
# ir_values_obj = self.pool.get('ir.values')
|
||||
# data_obj = self.pool.get('ir.model.data')
|
||||
# menu_obj = self.pool.get('ir.ui.menu')
|
||||
# result = {}
|
||||
# invoicing_groups_id = [gid.id for gid in data_obj.get_object(cr, uid, 'sale', 'menu_invoicing_sales_order_lines').groups_id]
|
||||
# picking_groups_id = [gid.id for gid in data_obj.get_object(cr, uid, 'sale', 'menu_action_picking_list_to_invoice').groups_id]
|
||||
# group_id = data_obj.get_object(cr, uid, 'base', 'group_sale_salesman').id
|
||||
# for menu in ir_values_obj.get(cr, uid, 'default', False, ['ir.ui.menu']):
|
||||
# if menu[1] == 'groups_id' and group_id in menu[2][0]:
|
||||
# if group_id in invoicing_groups_id:
|
||||
# result['sale_orders'] = True
|
||||
# if group_id in picking_groups_id:
|
||||
# result['deli_orders'] = True
|
||||
# for res in ir_values_obj.get(cr, uid, 'default', False, ['sale.order']):
|
||||
# result[res[1]] = res[2]
|
||||
# return result
|
||||
#
|
||||
# def default_get(self, cr, uid, fields_list, context=None):
|
||||
# result = super(purchase_configuration, self).default_get(
|
||||
# cr, uid, fields_list, context=context)
|
||||
# for method in dir(self):
|
||||
# if method.startswith('get_default_'):
|
||||
# result.update(getattr(self, method)(cr, uid, [], context))
|
||||
# return result
|
||||
#
|
||||
_defaults = {
|
||||
'default_method': lambda s,c,u,ctx: s.pool.get('purchase.order').default_get(c,u,['invoice_method'],context=ctx)['invoice_method'],
|
||||
}
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
ids = super(purchase_configuration, self).create(cr, uid, vals, context=context)
|
||||
self.execute(cr, uid, [ids], vals, context=context)
|
||||
return ids
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
self.execute(cr, uid, ids, vals, context=context)
|
||||
return super(purchase_configuration, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def execute(self, cr, uid, ids, vals, context=None):
|
||||
#TODO: TO BE IMPLEMENTED
|
||||
for method in dir(self):
|
||||
if method.startswith('set_'):
|
||||
getattr(self, method)(cr, uid, ids, vals, context)
|
||||
return True
|
||||
|
||||
# def set_installed_modules(self, cr, uid, ids, vals, context=None):
|
||||
# if vals.get('task_work'):
|
||||
# vals.update({'module_project_timesheet': True, 'module_project_mrp': True})
|
||||
# else:
|
||||
# vals.update({'module_project_timesheet': False, 'module_project_mrp': False})
|
||||
#
|
||||
# super(sale_configuration, self).set_installed_modules(cr, uid, ids, vals, context=context)
|
||||
|
||||
# def set_sale_defaults(self, cr, uid, ids, vals, context=None):
|
||||
# ir_values_obj = self.pool.get('ir.values')
|
||||
# data_obj = self.pool.get('ir.model.data')
|
||||
# menu_obj = self.pool.get('ir.ui.menu')
|
||||
# res = {}
|
||||
# wizard = self.browse(cr, uid, ids)[0]
|
||||
# group_id = data_obj.get_object(cr, uid, 'base', 'group_sale_salesman').id
|
||||
#
|
||||
# if wizard.sale_orders:
|
||||
# menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_invoicing_sales_order_lines').id
|
||||
# menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['ir.ui.menu'], [(4,group_id)])
|
||||
#
|
||||
# if wizard.deli_orders:
|
||||
# menu_id = data_obj.get_object(cr, uid, 'sale', 'menu_action_picking_list_to_invoice').id
|
||||
# menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_id)]})
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'groups_id', ['ir.ui.menu'], [(4,group_id)])
|
||||
#
|
||||
# if wizard.picking_policy:
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'picking_policy', ['sale.order'], 'one')
|
||||
#
|
||||
# if wizard.time_unit:
|
||||
# prod_id = data_obj.get_object(cr, uid, 'product', 'product_consultant').id
|
||||
# product_obj = self.pool.get('product.product')
|
||||
# product_obj.write(cr, uid, prod_id, {'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
|
||||
#
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
|
||||
# if wizard.task_work and wizard.time_unit:
|
||||
# company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
|
||||
# self.pool.get('res.company').write(cr, uid, [company_id], {
|
||||
# 'project_time_mode_id': wizard.time_unit.id
|
||||
# }, context=context)
|
||||
#
|
||||
# return res
|
||||
#
|
||||
# def onchange_tax_policy(self, cr, uid, ids, tax_policy, context=None):
|
||||
# self.set_tax_policy(cr, uid, ids, {'tax_policy': tax_policy}, context=context)
|
||||
# return {'value': {}}
|
||||
#
|
||||
# def set_default_taxes(self, cr, uid, ids, vals, context=None):
|
||||
# ir_values_obj = self.pool.get('ir.values')
|
||||
# taxes = self._check_default_tax(cr, uid, context=context)
|
||||
# if isinstance(vals.get('tax_value'), list):
|
||||
# taxes = vals.get('tax_value')
|
||||
# if taxes:
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'tax_id', ['sale.order'], taxes[0])
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'tax_id', ['sale.order.line'], taxes)
|
||||
# ir_values_obj.set(cr, uid, 'default', False, 'taxes_id', ['product.product'], taxes)
|
||||
|
||||
purchase_configuration()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,63 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_purchase_config" model="ir.ui.view">
|
||||
<field name="name">Purchase Application</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="base.view_res_config_settings"/>
|
||||
<field name="arch" type="xml">
|
||||
<form position ="replace">
|
||||
<form string ="Purchase Application">
|
||||
<separator string="Default Invoicing Control" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="default_method"/>
|
||||
</group>
|
||||
|
||||
<separator string="Purchase Order" colspan="4"/>
|
||||
<group colspan="4" col="8" name="Purchase_order">
|
||||
<group colspan="4" col="4">
|
||||
<field name="group_purchase_pricelist_per_supplier"/>
|
||||
<newline/>
|
||||
<!--group col="2" colspan="1">
|
||||
<field name="tax_policy" on_change="onchange_tax_policy(tax_policy)"/>
|
||||
</group-->
|
||||
<newline/>
|
||||
<field name="module_warning"/>
|
||||
<newline/>
|
||||
<field name="module_purchase_analytic_plans"/>
|
||||
<newline/>
|
||||
</group>
|
||||
<group colspan="4" col="4">
|
||||
<newline/>
|
||||
<field name="group_purchase_uom_per_product"/>
|
||||
<newline/>
|
||||
<field name="module_purchase_double_validation"/>
|
||||
<newline/>
|
||||
<field name="module_purchase_requisition"/>
|
||||
<newline/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
<separator string="Products" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="module_product_manufacturer"/>
|
||||
</group>
|
||||
</form>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purchase_configuration" model="ir.actions.act_window">
|
||||
<field name="name">Configure Purchase Application</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">res.config.settings</field>
|
||||
<field name="view_id" ref="view_purchase_config"/>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="base.menu_purchse_config" name="Purchase" parent="base.menu_config" sequence="1" action="purchase.action_purchase_configuration"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -22,18 +22,29 @@
|
|||
from osv import fields, osv
|
||||
|
||||
class purchase_double_validation_installer(osv.osv_memory):
|
||||
_name = 'purchase.double.validation.installer'
|
||||
_inherit = 'res.config'
|
||||
_inherit = 'res.config.settings'
|
||||
_columns = {
|
||||
'limit_amount': fields.integer('Maximum Purchase Amount', required=True, help="Maximum amount after which validation of purchase is required."),
|
||||
}
|
||||
|
||||
def get_default_installed_modules(self, cr, uid, ids, context=None):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
transition_obj = self.pool.get('workflow.transition')
|
||||
installed_modules = super(purchase_double_validation_installer, self).get_default_installed_modules(cr, uid, ids, context=context)
|
||||
if installed_modules.get('module_purchase_double_validation'):
|
||||
tra_id = data_obj.get_object(cr, uid, 'purchase_double_validation', 'trans_waiting_confirmed')
|
||||
condition = transition_obj.browse(cr, uid, tra_id.id).condition
|
||||
con = condition.split('<', 1 );
|
||||
installed_modules.update({'limit_amount': int(con[1])})
|
||||
return installed_modules
|
||||
|
||||
_defaults = {
|
||||
'limit_amount': 5000,
|
||||
}
|
||||
|
||||
def execute(self, cr, uid, ids, context=None):
|
||||
def execute(self, cr, uid, ids, vals, context=None):
|
||||
data = self.read(cr, uid, ids, context=context)
|
||||
super(purchase_double_validation_installer, self).execute(cr, uid, ids, vals, context=context)
|
||||
if not data:
|
||||
return {}
|
||||
amt = data[0]['limit_amount']
|
||||
|
@ -45,7 +56,7 @@ class purchase_double_validation_installer(osv.osv_memory):
|
|||
confirm_id = data_pool.browse(cr, uid, confirm, context=context).res_id
|
||||
transition_obj.write(cr, uid, waiting_id, {'condition': 'amount_total>=%s' % (amt)})
|
||||
transition_obj.write(cr, uid, confirm_id, {'condition': 'amount_total<%s' % (amt)})
|
||||
return {}
|
||||
return True
|
||||
|
||||
purchase_double_validation_installer()
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<data>
|
||||
<!-- configartion view -->
|
||||
|
||||
<record id="view_config_purchase_limit_amount" model="ir.ui.view">
|
||||
<!-- record id="view_config_purchase_limit_amount" model="ir.ui.view">
|
||||
<field name="name">Configure Limit Amount for Purchase</field>
|
||||
<field name="model">purchase.double.validation.installer</field>
|
||||
<field name="type">form</field>
|
||||
|
@ -38,23 +38,23 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</record-->
|
||||
|
||||
<!-- register configuration wizard -->
|
||||
<record id="config_wizard_step_purchase_limit_amount" model="ir.actions.todo">
|
||||
<!--record id="config_wizard_step_purchase_limit_amount" model="ir.actions.todo">
|
||||
<field name="action_id" ref="action_config_purchase_limit_amount"/>
|
||||
<field name="category_id" ref="purchase.category_purchase_config"/>
|
||||
<field name="type">once</field>
|
||||
</record>
|
||||
</record-->
|
||||
|
||||
<record id="view_purchase_config" model="ir.ui.view">
|
||||
<field name="name">board.purchase.form</field>
|
||||
<field name="model">board.board</field>
|
||||
<record id="view_double_purchase_config" model="ir.ui.view">
|
||||
<field name="name">Purchase Application</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="purchase.view_purchase_config"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="module_purchase_double_validation" position="after">
|
||||
<field name="purchase_limit" nolabel="1"/>
|
||||
<field name="limit_amount" nolabel="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue