[IMP] improved code for invoice control method, taxes, groups and tooltips
bzr revid: tpa@tinyerp.com-20120313120151-i8r76ft8nkipxoo9
This commit is contained in:
parent
5be3d4c4e9
commit
ee473d94c1
|
@ -207,6 +207,7 @@ class purchase_order(osv.osv):
|
|||
'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'),
|
||||
'create_uid': fields.many2one('res.users', 'Responsible'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True,select=1),
|
||||
'tax_id': fields.many2one('account.tax', 'Tax'),
|
||||
}
|
||||
_defaults = {
|
||||
'date_order': fields.date.context_today,
|
||||
|
@ -295,7 +296,7 @@ class purchase_order(osv.osv):
|
|||
return True
|
||||
|
||||
def _prepare_inv_line(self, cr, uid, account_id, order_line, context=None):
|
||||
"""Collects require data from purchase order line that is used to create invoice line
|
||||
"""Collects require data from purchase order line that is used to create invoice line
|
||||
for that purchase order line
|
||||
:param account_id: Expense account of the product of PO line if any.
|
||||
:param browse_record order_line: Purchase order line browse record
|
||||
|
@ -379,7 +380,7 @@ class purchase_order(osv.osv):
|
|||
'address_invoice_id': order.partner_address_id.id,
|
||||
'address_contact_id': order.partner_address_id.id,
|
||||
'journal_id': len(journal_ids) and journal_ids[0] or False,
|
||||
'invoice_line': [(6, 0, inv_lines)],
|
||||
'invoice_line': [(6, 0, inv_lines)],
|
||||
'origin': order.name,
|
||||
'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
|
||||
'payment_term': order.partner_id.property_payment_term and order.partner_id.property_payment_term.id or False,
|
||||
|
@ -420,7 +421,7 @@ class purchase_order(osv.osv):
|
|||
if inv:
|
||||
wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_cancel', cr)
|
||||
self.write(cr,uid,ids,{'state':'cancel'})
|
||||
|
||||
|
||||
for (id, name) in self.name_get(cr, uid, ids):
|
||||
wf_service.trg_validate(uid, 'purchase.order', id, 'purchase_cancel', cr)
|
||||
message = _("Purchase order '%s' is cancelled.") % name
|
||||
|
@ -439,7 +440,7 @@ class purchase_order(osv.osv):
|
|||
'company_id': order.company_id.id,
|
||||
'move_lines' : [],
|
||||
}
|
||||
|
||||
|
||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
|
||||
return {
|
||||
'name': order.name + ': ' + (order_line.name or ''),
|
||||
|
@ -480,7 +481,7 @@ class purchase_order(osv.osv):
|
|||
will be added. A new picking will be created if omitted.
|
||||
:return: list of IDs of pickings used/created for the given order lines (usually just one)
|
||||
"""
|
||||
if not picking_id:
|
||||
if not picking_id:
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context))
|
||||
todo_moves = []
|
||||
stock_move = self.pool.get('stock.move')
|
||||
|
@ -732,7 +733,7 @@ class purchase_order_line(osv.osv):
|
|||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
|
||||
res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom_id or False}}
|
||||
if not product_id:
|
||||
return res
|
||||
|
@ -756,7 +757,7 @@ class purchase_order_line(osv.osv):
|
|||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
product = product_product.browse(cr, uid, product_id, context=context_partner)
|
||||
res['value'].update({'name': product.name, 'notes': notes or product.description_purchase})
|
||||
|
||||
|
||||
# - set a domain on product_uom
|
||||
res['domain'] = {'product_uom': [('category_id','=',product.uom_id.category_id.id)]}
|
||||
|
||||
|
@ -764,7 +765,7 @@ class purchase_order_line(osv.osv):
|
|||
product_uom_po_id = product.uom_po_id.id
|
||||
if not uom_id:
|
||||
uom_id = product_uom_po_id
|
||||
|
||||
|
||||
if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id:
|
||||
res['warning'] = {'title': _('Warning'), 'message': _('Selected UOM does not belong to the same category as the product UOM')}
|
||||
uom_id = product_uom_po_id
|
||||
|
@ -794,7 +795,7 @@ class purchase_order_line(osv.osv):
|
|||
# - determine price_unit and taxes_id
|
||||
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
||||
product.id, qty or 1.0, partner_id, {'uom': uom_id, 'date': date_order})[pricelist_id]
|
||||
|
||||
|
||||
taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id))
|
||||
fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False
|
||||
taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes)
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
<menuitem
|
||||
id="menu_purchase_unit_measure_purchase" name="Units of Measure"
|
||||
parent="purchase.menu_product_in_config_purchase" sequence="20" groups="base.group_purchase_uom_per_product"/>
|
||||
parent="purchase.menu_product_in_config_purchase" sequence="20" groups="base.group_sale_uom_per_product"/>
|
||||
|
||||
<menuitem
|
||||
action="product.product_uom_categ_form_action" id="menu_purchase_uom_categ_form_action"
|
||||
|
@ -182,15 +182,16 @@
|
|||
<field name="date_planned"/>
|
||||
<field name="name"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom" groups="base.group_purchase_uom_per_product"/>
|
||||
<field name="product_uom" groups="base.group_sale_uom_per_product"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="price_subtotal"/>
|
||||
</tree>
|
||||
<!-- default form view -->
|
||||
</field>
|
||||
<group col="7" colspan="4">
|
||||
<field name="amount_untaxed" sum="Untaxed amount"/>
|
||||
<field name="amount_tax"/>
|
||||
<field name="amount_untaxed" sum="Untaxed amount" groups="base.group_purchase_taxes_on_order_line,base.group_purchase_taxes_global_on_order"/>
|
||||
<field name="amount_tax" groups="base.group_purchase_taxes_on_order_line,base.group_purchase_taxes_global_on_order"/>
|
||||
<field name="tax_id" groups="base.group_sale_taxes_global_on_order"/>
|
||||
<field name="amount_total" sum="Total amount"/>
|
||||
<button name="button_dummy" states="draft" string="Compute" type="object" icon="gtk-execute"/>
|
||||
</group>
|
||||
|
@ -304,7 +305,7 @@
|
|||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="purchase_order_tree" model="ir.ui.view">
|
||||
<field name="name">purchase.order.tree</field>
|
||||
<field name="model">purchase.order</field>
|
||||
|
@ -361,13 +362,13 @@
|
|||
<page string="Order Line">
|
||||
<field name="product_id" colspan="4" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)" required="1"/>
|
||||
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)"/>
|
||||
<field name="product_uom" groups="base.group_purchase_uom_per_product" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)"/>
|
||||
<field name="product_uom" groups="base.group_sale_uom_per_product" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)"/>
|
||||
<field colspan="4" name="name"/>
|
||||
<field name="date_planned" widget="date"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="account_analytic_id" colspan="4" groups="analytic.group_analytic_accounting" domain="[('parent_id','!=',False)]" />
|
||||
<group colspan="4" col="4" groups="base.group_extended">
|
||||
<group colspan="4" col="4" groups="base.group_purchase_taxes_on_order_line">
|
||||
<separator colspan="4" string="Taxes"/>
|
||||
<field colspan="4" nolabel="1" name="taxes_id"
|
||||
domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
|
||||
|
@ -403,7 +404,7 @@
|
|||
<field name="product_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom" groups="base.group_purchase_uom_per_product"/>
|
||||
<field name="product_uom" groups="base.group_sale_uom_per_product"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="date_planned" widget="date" width="135"/>
|
||||
<field name="state" invisible="1"/>
|
||||
|
@ -424,7 +425,7 @@
|
|||
<field name="order_id"/>
|
||||
<field name="product_id" readonly="1" />
|
||||
<field name="product_qty" readonly="1" />
|
||||
<field name="product_uom" readonly="1" groups="base.group_purchase_uom_per_product"/>
|
||||
<field name="product_uom" readonly="1" groups="base.group_sale_uom_per_product"/>
|
||||
<field colspan="4" name="name"/>
|
||||
<field name="date_planned" widget="date" readonly="1"/>
|
||||
<field name="price_unit"/>
|
||||
|
|
|
@ -24,15 +24,16 @@ import pooler
|
|||
from tools.translate import _
|
||||
|
||||
class purchase_configuration(osv.osv_memory):
|
||||
_name = 'purchase.configuration'
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
_columns = {
|
||||
'default_method' : fields.selection(
|
||||
'default_invoice_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 , help="You can set Invoicing Control Method."),
|
||||
'module_purchase_analytic_plans': fields.boolean('Purchase Analytic Plan',
|
||||
], 'Invoicing Control Method', required=True, default_model='purchase.order' , 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
|
||||
a line on a supplier purchase order into several accounts and analytic plans.
|
||||
|
@ -42,14 +43,14 @@ class purchase_configuration(osv.osv_memory):
|
|||
help="""To trigger warnings in OpenERP objects.
|
||||
Warning messages can be displayed for objects like sale order, purchase order, picking and invoice. The message is triggered by the form's onchange event.
|
||||
It installs the warning module."""),
|
||||
'module_product_manufacturer': fields.boolean("Define a manufacturer on products",
|
||||
help="""TYou can now define the following for a product:
|
||||
'module_product_manufacturer': fields.boolean("Define a manufacturer of products",
|
||||
help="""This allows you to define the following for a product:
|
||||
* Manufacturer
|
||||
* Manufacturer Product Name
|
||||
* Manufacturer Product Code
|
||||
* Product Attributes.
|
||||
It installs the product_manufacturer module."""),
|
||||
'module_purchase_double_validation': fields.boolean("Configure Limit amount",
|
||||
'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."""),
|
||||
'module_purchase_requisition' : fields.boolean("Track the best price with Purchase Requisition",
|
||||
|
@ -69,15 +70,27 @@ class purchase_configuration(osv.osv_memory):
|
|||
'group_purchase_taxes_on_order_line':fields.boolean("On order line", group='base.group_user', implied_group='base.group_purchase_taxes_on_order_line'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
res = super(purchase_configuration, self).default_get(cr, uid, fields, context)
|
||||
if res.get('group_purchase_taxes_global_on_order'):
|
||||
res.update({'tax_policy': 'global_on_order'})
|
||||
elif res.get('group_purchase_taxes_on_order_line'):
|
||||
res.update({'tax_policy': 'on_order_line'})
|
||||
else:
|
||||
res.update({'tax_policy': 'no_tax'})
|
||||
return res
|
||||
|
||||
|
||||
_defaults = {
|
||||
'default_method': lambda s,c,u,ctx: s.pool.get('purchase.order').default_get(c,u,['invoice_method'],context=ctx)['invoice_method'],
|
||||
'default_invoice_method': lambda s,c,u,ctx: s.pool.get('purchase.order').default_get(c,u,['invoice_method'],context=ctx)['invoice_method'],
|
||||
'tax_policy': 'global_on_order',
|
||||
}
|
||||
|
||||
def _check_default_tax(self, cr, uid, context=None):
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
for tax in ir_values_obj.get(cr, uid, 'default', False, ['product.product']):
|
||||
if tax[1] == 'taxes_id':
|
||||
if tax[1] == 'supplier_taxes_id':
|
||||
return tax[2]
|
||||
return False
|
||||
|
||||
|
@ -86,13 +99,11 @@ class purchase_configuration(osv.osv_memory):
|
|||
taxes = self._check_default_tax(cr, uid, context=context)
|
||||
if taxes:
|
||||
ir_values_obj.set(cr, uid, 'default', False, 'tax_id', ['purchase.order'], taxes[0])
|
||||
ir_values_obj.set(cr, uid, 'default', False, 'tax_id', ['purchase.order.line'], taxes)
|
||||
ir_values_obj.set(cr, uid, 'default', False, 'taxes_id', ['product.product'], taxes)
|
||||
ir_values_obj.set(cr, uid, 'default', False, 'taxes_id', ['purchase.order.line'], taxes)
|
||||
ir_values_obj.set(cr, uid, 'default', False, 'supplier_taxes_id', ['product.product'], taxes)
|
||||
|
||||
def onchange_tax_policy(self, cr, uid, ids, tax_policy, context=None):
|
||||
res = {'value': {}}
|
||||
if ids:
|
||||
self.set_tax_policy(cr, uid, ids, context=context)
|
||||
if tax_policy == 'global_on_order':
|
||||
res['value'].update({'group_purchase_taxes_global_on_order': True})
|
||||
res['value'].update({'group_purchase_taxes_on_order_line': False})
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
<record id="view_purchase_configuration" model="ir.ui.view">
|
||||
<field name="name">Purchase Application</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="model">purchase.configuration</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Purchase Application">
|
||||
<separator string="Default Invoicing Control" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="default_method"/>
|
||||
<group colspan="2" col="4">
|
||||
<field name="default_invoice_method" />
|
||||
</group>
|
||||
|
||||
<separator string="Purchase Order" colspan="4"/>
|
||||
|
@ -30,7 +30,7 @@
|
|||
</group>
|
||||
<group colspan="4" col="4">
|
||||
<newline/>
|
||||
<field name="group_purchase_uom_per_product"/>
|
||||
<field name="group_sale_uom_per_product"/>
|
||||
<newline/>
|
||||
<field name="module_purchase_double_validation"/>
|
||||
<newline/>
|
||||
|
@ -50,7 +50,7 @@
|
|||
<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="res_model">purchase.configuration</field>
|
||||
<field name="view_id" ref="view_purchase_configuration"/>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
|
|
|
@ -1,49 +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 osv import fields, osv
|
||||
|
||||
class res_company(osv.osv):
|
||||
_inherit = "res.company"
|
||||
_columns = {
|
||||
'paypal_account': fields.char("Paypal Account", size=128, help="Paypal username (usually email) for receiving online payments."),
|
||||
'overdue_msg': fields.text('Overdue Payments Message', translate=True),
|
||||
'property_reserve_and_surplus_account': fields.property(
|
||||
'account.account',
|
||||
type='many2one',
|
||||
relation='account.account',
|
||||
string="Reserve and Profit/Loss Account",
|
||||
view_load=True,
|
||||
domain="[('type', '=', 'other')]",
|
||||
help="This account is used for transferring Profit/Loss (If It is Profit: Amount will be added, Loss : Amount will be deducted.), as calculated in Profit & Loss Report"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'overdue_msg': '''Our records indicate that the following payments are still due. If the amount
|
||||
has already been paid, please disregard this notice. However, if you have any
|
||||
queries regarding your account, please contact us.
|
||||
Thank you in advance.
|
||||
'''
|
||||
}
|
||||
|
||||
res_company()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -22,9 +22,10 @@
|
|||
from osv import fields, osv
|
||||
|
||||
class purchase_double_validation_installer(osv.osv_memory):
|
||||
_inherit = 'res.config.settings'
|
||||
_name = 'purchase.double.validation.installer'
|
||||
_inherit = 'purchase.configuration'
|
||||
_columns = {
|
||||
'limit_amount': fields.integer('Maximum Purchase Amount', default_model='model.name',required=True, help="Maximum amount after which validation of purchase is required."),
|
||||
'limit_amount': fields.integer('Maximum Purchase Amount',required=True, help="Maximum amount after which validation of purchase is required."),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
|
@ -42,9 +43,9 @@ class purchase_double_validation_installer(osv.osv_memory):
|
|||
'limit_amount': 5000,
|
||||
}
|
||||
|
||||
def execute(self, cr, uid, ids, vals, context=None):
|
||||
def execute(self, cr, uid, ids, context=None):
|
||||
data = self.read(cr, uid, ids, context=context)
|
||||
super(purchase_double_validation_installer, self).execute(cr, uid, ids, vals)
|
||||
super(purchase_double_validation_installer, self).execute(cr, uid, ids, context)
|
||||
if not data:
|
||||
return {}
|
||||
amt = data[0]['limit_amount']
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<record id="view_double_purchase_configuration" model="ir.ui.view">
|
||||
<field name="name">Purchase Application</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="model">purchase.double.validation.installer</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="purchase.view_purchase_configuration"/>
|
||||
<field name="arch" type="xml">
|
||||
|
|
Loading…
Reference in New Issue