bzr revid: rvalyi@gmail.com-20100723145429-utly4nv20yj1ll45
This commit is contained in:
Raphaël Valyi
2010-07-23 11:54:29 -03:00
20 changed files with 257 additions and 171 deletions
+54 -53
View File
@@ -248,59 +248,59 @@ class account_account(osv.osv):
def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
query='', query_params=()):
""" compute the balance, debit and/or credit for the provided
account ids
Arguments:
`ids`: account ids
`field_names`: the fields to compute (a list of any of
'balance', 'debit' and 'credit')
`arg`: unused fields.function stuff
`query`: additional query filter (as a string)
`query_params`: parameters for the provided query string
(__compute will handle their escaping) as a
tuple
"""
mapping = {
'balance': "COALESCE(SUM(l.debit),0) " \
"- COALESCE(SUM(l.credit), 0) as balance",
'debit': "COALESCE(SUM(l.debit), 0) as debit",
'credit': "COALESCE(SUM(l.credit), 0) as credit"
}
#get all the necessary accounts
children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context)
#compute for each account the balance/debit/credit from the move lines
accounts = {}
if children_and_consolidated:
aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
""" compute the balance, debit and/or credit for the provided
account ids
Arguments:
`ids`: account ids
`field_names`: the fields to compute (a list of any of
'balance', 'debit' and 'credit')
`arg`: unused fields.function stuff
`query`: additional query filter (as a string)
`query_params`: parameters for the provided query string
(__compute will handle their escaping) as a
tuple
"""
mapping = {
'balance': "COALESCE(SUM(l.debit),0) " \
"- COALESCE(SUM(l.credit), 0) as balance",
'debit': "COALESCE(SUM(l.debit), 0) as debit",
'credit': "COALESCE(SUM(l.credit), 0) as credit"
}
#get all the necessary accounts
children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context)
#compute for each account the balance/debit/credit from the move lines
accounts = {}
if children_and_consolidated:
aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
wheres = [""]
if query.strip():
wheres.append(query.strip())
if aml_query.strip():
wheres.append(aml_query.strip())
filters = " AND ".join(wheres)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Filters: %s'%filters)
# IN might not work ideally in case there are too many
# children_and_consolidated, in that case join on a
# values() e.g.:
# SELECT l.account_id as id FROM account_move_line l
# INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
# ON l.account_id = tmp.id
# or make _get_children_and_consol return a query and join on that
request = ("SELECT l.account_id as id, " +\
' , '.join(map(mapping.__getitem__, field_names)) +
" FROM account_move_line l" \
" WHERE l.account_id IN %s " \
+ filters +
" GROUP BY l.account_id")
params = (tuple(children_and_consolidated),) + query_params
cr.execute(request, params)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Status: %s'%cr.statusmessage)
wheres = [""]
if query.strip():
wheres.append(query.strip())
if aml_query.strip():
wheres.append(aml_query.strip())
filters = " AND ".join(wheres)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Filters: %s'%filters)
# IN might not work ideally in case there are too many
# children_and_consolidated, in that case join on a
# values() e.g.:
# SELECT l.account_id as id FROM account_move_line l
# INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
# ON l.account_id = tmp.id
# or make _get_children_and_consol return a query and join on that
request = ("SELECT l.account_id as id, " +\
' , '.join(map(mapping.__getitem__, field_names)) +
" FROM account_move_line l" \
" WHERE l.account_id IN %s " \
+ filters +
" GROUP BY l.account_id")
params = (tuple(children_and_consolidated),) + query_params
cr.execute(request, params)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Status: %s'%cr.statusmessage)
for res in cr.dictfetchall():
accounts[res['id']] = res
for res in cr.dictfetchall():
accounts[res['id']] = res
# consolidate accounts with direct children
children_and_consolidated.reverse()
@@ -2539,9 +2539,9 @@ class wizard_multi_charts_accounts(osv.osv_memory):
'account_paid_id': acc_template_ref[value['account_paid_id']],
})
# Creating Journals
# Creating Journals Sales and Purchase
vals_journal={}
data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_view')])
data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
data = data_pool.browse(cr, uid, data_id[0])
view_id = data.res_id
@@ -2573,6 +2573,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
vals_journal['type'] = 'purchase'
vals_journal['code'] = _('EXJ')
vals_journal['sequence_id'] = seq_id_purchase
vals_journal['view_id'] = view_id
if obj_multi.chart_template_id.property_account_payable:
vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
+31 -3
View File
@@ -183,7 +183,7 @@ class account_move_line(osv.osv):
# Compute the current move
move_id = False
partner_id = False
if context.get('journal_id',False) and context.get('period_id',False):
if context.get('journal_id', False) and context.get('period_id', False):
if 'move_id' in fields:
cr.execute('select move_id \
from \
@@ -199,6 +199,7 @@ class account_move_line(osv.osv):
return data
else:
data['move_id'] = move_id
if 'date' in fields:
cr.execute('select date \
from \
@@ -214,7 +215,6 @@ class account_move_line(osv.osv):
period = period_obj.browse(cr, uid, context['period_id'],
context=context)
data['date'] = period.date_start
if not move_id:
return data
@@ -786,6 +786,31 @@ class account_move_line(osv.osv):
return j+(p and (':'+p) or '')
return False
# def onchange_date(self, cr, user, ids, date, context={}):
# """
# Returns a dict that contains new values and context
# @param cr: A database cursor
# @param user: ID of the user currently logged in
# @param date: latest value from user input for field date
# @param args: other arguments
# @param context: context arguments, like lang, time zone
# @return: Returns a dict which contains new values, and context
# """
# res = {}
# period_pool = self.pool.get('account.period')
# pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
# if pids:
# res.update({
# 'period_id':pids[0]
# })
# context.update({
# 'period_id':pids[0]
# })
# return {
# 'value':res,
# 'context':context,
# }
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
result = super(osv.osv, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu)
if view_type != 'tree':
@@ -848,11 +873,14 @@ class account_move_line(osv.osv):
elif field == 'credit':
attrs.append('sum="Total credit"')
elif field == 'account_tax_id':
attrs.append('domain="[(\'parent_id\',\'=\',False)]"')
attrs.append('domain="[(\'parent_id\',\'=\',False), (\'type_tax_use\',\'=\',context.get(journal_id.type, \'sale\'))]"')
elif field == 'account_id' and journal.id:
attrs.append('domain="[(\'journal_id\', \'=\', '+str(journal.id)+'),(\'type\',\'&lt;&gt;\',\'view\'), (\'type\',\'&lt;&gt;\',\'closed\')]" on_change="onchange_account_id(account_id, partner_id)"')
elif field == 'partner_id':
attrs.append('on_change="onchange_partner_id(move_id, partner_id, account_id, debit, credit, date, journal_id)"')
# elif field == 'date':
# attrs.append('on_change="onchange_date(date)"')
# if field.readonly:
# attrs.append('readonly="1"')
# if field.required:
+20 -11
View File
@@ -269,9 +269,9 @@
<field colspan="4" name="name" select="1"/>
<field name="field" select="1"/>
<field name="sequence"/>
<newline/>
<field name="readonly"/>
<field name="required"/>
<!-- <newline/>-->
<!-- <field name="readonly"/>-->
<!-- <field name="required"/>-->
</form>
</field>
</record>
@@ -283,8 +283,8 @@
<tree string="Journal Column">
<field name="sequence"/>
<field name="name"/>
<field name="required"/>
<field name="readonly"/>
<!-- <field name="required"/>-->
<!-- <field name="readonly"/>-->
</tree>
</field>
</record>
@@ -295,11 +295,18 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Journal View">
<field colspan="4" name="name" select="1"/>
<field name="name" select="1"/>
<field colspan="4" name="columns_id" nolabel="1" widget="one2many_list"/>
</form>
</field>
</record>
<record id="action_account_journal_view" model="ir.actions.act_window">
<field name="name">Journal Views</field>
<field name="res_model">account.journal.view</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem action="action_account_journal_view" id="menu_action_account_journal_view" parent="account.menu_low_level"/>
<!--
# Account Journal
@@ -953,7 +960,7 @@
<field eval="9" name="priority"/>
<field name="arch" type="xml">
<form string="Account Entry Line">
<notebook>
<notebook colspan="4">
<page string="Information">
<separator colspan="4" string="General Information"/>
<field name="name" select="1"/>
@@ -1001,8 +1008,11 @@
<search string="Search Entry Lines">
<group col='10' colspan='4'>
<filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Entry Lines"/>
<filter icon="terp-camera_test" string="Posted" domain="[('state','=','valid')]" help="Posted Entry Lines"/>
<separator orientation="vertical"/>
<filter icon="terp-camera_test" string="Posted" domain="[('state','=','valid')]" help="Posted Entry Lines"/>
<filter icon="terp-stock_symbol-selection" string="Unposted" domain="[('move_id.state','=','draft')]" help="Unposted Entry Lines"/>
<separator orientation="vertical"/>
<filter icon="terp-stock_symbol-selection" string="Unreconciled" domain="[('reconcile_id','=',False), ('account_id.type','in',['receivable', 'payable'])]" help="Unreconciled Entry Lines"/>
<field name="date" select='1'/>
<field name="account_id" select='1'/>
<field name="partner_id" select='1'>
@@ -1012,8 +1022,8 @@
</group>
<newline/>
<group col="10" colspan="4">
<field name="journal_id" widget="selection" context="{'journal_id':self, 'visible_id':self or 0, 'normal_view':False}"/>
<field name="period_id" widget="selection" context="{'period_id':self}"/>
<field name="journal_id" required="1" widget="selection" context="{'journal_id':self, 'visible_id':self or 0, 'normal_view':False}"/>
<field name="period_id" required="1" widget="selection" context="{'period_id':self}"/>
</group>
</search>
</field>
@@ -1255,7 +1265,6 @@
<field name="view_id" ref="view_move_line_tree"/>
<field name="search_view_id" ref="view_account_move_line_filter"/>
<field name="domain">[('journal_id.type', 'in', ['purchase', 'sale_refund'])]</field>
<field name="context">{'journal_id':1}</field>
</record>
<menuitem action="action_account_moves_purchase" id="menu_eaction_account_moves_purchase" parent="menu_finance_payables"/>
+5 -2
View File
@@ -296,9 +296,12 @@ class account_installer(osv.osv_memory):
'account_paid_id': acc_template_ref[value['account_paid_id']],
})
# Creating Journals
# Creating Journals Sales and Purchase
vals_journal={}
view_id = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Journal View')])[0]
data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
data = data_pool.browse(cr, uid, data_id[0])
view_id = data.res_id
seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0]
if seq_journal:
+3 -1
View File
@@ -233,7 +233,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
"Partner: %s" % (lead.partner_id and lead.partner_id.name_get()[0][1]),
"Contact: %s" % (pa.name or ''),
"Title: %s" % (pa.title or ''),
"Function: %s" % (pa.function and pa.function.name_get()[0][1] or ''),
"Function: %s" % (pa.function or ''),
"Street: %s" % (pa.street or ''),
"Street2: %s" % (pa.street2 or ''),
"Zip: %s" % (pa.zip or ''),
@@ -244,6 +244,8 @@ class crm_lead_forward_to_partner(osv.osv_memory):
"Phone: %s" % (pa.phone or ''),
"Fax: %s" % (pa.fax or ''),
"Mobile: %s" % (pa.mobile or ''),
"Lead Category: %s" % (lead.categ_id and lead.categ_id.name or ''),
"Details: %s" % (lead.description or ''),
]
return "\n".join(body + ['---'])
-1
View File
@@ -72,7 +72,6 @@
'wizard/mrp_change_standard_price_view.xml',
# 'wizard/mrp_track_prod_view.xml',
'mrp_view.xml',
'mrp_wizard.xml',
'mrp_report.xml',
'company_view.xml',
'process/stockable_product_process.xml',
+18 -11
View File
@@ -48,10 +48,10 @@ class mrp_workcenter(osv.osv):
'time_cycle': fields.float('Time for 1 cycle (hour)', help="Time in hours for doing one cycle."),
'time_start': fields.float('Time before prod.', help="Time in hours for the setup."),
'time_stop': fields.float('Time after prod.', help="Time in hours for the cleaning."),
'costs_hour': fields.float('Cost per hour'),
'costs_hour': fields.float('Cost per hour', help="Specify Cost of Workcenter per hour."),
'costs_hour_account_id': fields.many2one('account.analytic.account', 'Hour Account', domain=[('type','<>','view')],
help="Complete this only if you want automatic analytic accounting entries on production orders."),
'costs_cycle': fields.float('Cost per cycle'),
'costs_cycle': fields.float('Cost per cycle', help="Specify Cost of Workcenter per cycle."),
'costs_cycle_account_id': fields.many2one('account.analytic.account', 'Cycle Account', domain=[('type','<>','view')],
help="Complete this only if you want automatic analytic accounting entries on production orders."),
'costs_journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal'),
@@ -636,13 +636,11 @@ class mrp_production(osv.osv):
move_obj.write(cr, uid, [production.move_prod_id.id],
{'location_id': production.location_dest_id.id})
message = ("%s %s %s %s %s %s") % (
_('Manufacturing Order '),
name,
_("scheduled the"),
datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d'),
_("for"),
production.product_id.name)
message = ("Manufacturing Order '%s' for %s %s is Ready to produce.") % (
name,
production.product_qty,
production.product_id.name,
)
self.log(cr, uid, production_id, message)
return True
@@ -741,7 +739,7 @@ class mrp_production(osv.osv):
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr)
message = _('Manufacturing order ') + " '" + production.name + "' "+ _("is finished.")
message = str(production_qty) + " '[" + production.product_id.code + '] ' + production.product_id.name + _("' have been manufactured for ") + production.name
self.log(cr, uid, production_id, message)
return True
@@ -911,7 +909,16 @@ class mrp_production(osv.osv):
proc_ids.append(proc_id)
wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
self.write(cr, uid, [production.id], {'picking_id': picking_id, 'move_lines': [(6,0,moves)], 'state':'confirmed'})
message = _('Manufacturing order ') + " '" + production.name + "' "+ _("is confirmed.")
message = ("%s '%s' %s %s %s %s %s %s.") % (
_('Manufacturing Order'),
production.name,
_('for'),
production.product_qty,
production.product_id.name,
_('scheduled for date '),
datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d'),
_('is waiting')
)
self.log(cr, uid, production.id, message)
return picking_id
-7
View File
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
</data>
</openerp>
+41 -47
View File
@@ -31,53 +31,46 @@ from tools.translate import _
class report_custom(report_rml):
def create_xml(self, cr, uid, ids, datas, context={}):
number = (datas.get('form', False) and datas['form']['number']) or 1
def process_bom(bom, currency_id):
pool = pooler.get_pool(cr.dbname)
product_pool = pool.get('product.product')
product_uom_pool = pool.get('product.uom')
supplier_info_pool = pool.get('product.supplierinfo')
workcenter_pool = pool.get('mrp.workcenter')
user_pool = pool.get('res.users')
bom_pool = pool.get('mrp.bom')
def process_bom(bom, currency_id, factor=1):
xml = '<row>'
sum = 0
sum_strd = 0
prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, bom['product_id'])
prod = product_pool.browse(cr, uid, bom['product_id'])
prod_name = bom['name']
prod_qtty = bom['product_qty']
prod_uom = prod.uom_id.name
prod_qtty = factor * bom['product_qty']
product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context)
level = 1
main_sp_price = ''
main_sp_name = ''
main_strd_price = ''
main_strd_price = ''
if prod.seller_ids and prod.seller_ids[0] :
main_sp_name = '<b>' + prod.seller_ids[0].name.name + '</b>\r\n'
pricelist_id = prod.seller_ids[0].name.property_product_pricelist_purchase.id
if pricelist_id:
pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
price = pooler.get_pool(cr.dbname).get('res.currency').compute(cr, uid, pricelist_obj.browse(cr, uid, pricelist_id).currency_id.id, currency_id, price)
else:
price = 0
main_sp_price = '%.2f' % price + '\r\n'
main_sp_price, main_sp_name , main_strd_price = '','',''
sellers, sellers_price = '',''
if prod.seller_id:
main_sp_name = "<b>%s</b>\r\n" %(prod.seller_id.name)
price = supplier_info_pool.price_get(cr, uid, prod.seller_id.id, prod.id, number*prod_qtty)[prod.seller_id.id]
price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, price, to_uom_id=product_uom.id)
main_sp_price = '%s\r\n' %(str(price))
sum += prod_qtty*price
std_price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id)
main_strd_price = str(std_price) + '\r\n'
sum_strd = prod_qtty*std_price
main_strd_price = '%.2f' % prod.standard_price + '\r\n'
sum_strd = prod_qtty*prod.standard_price
sellers = ''
sellers_price = ''
for seller_id in prod.seller_ids:
sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
pricelist_id = seller_id.name.property_product_pricelist_purchase.id
if pricelist_id:
pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
price = pooler.get_pool(cr.dbname).get('res.currency').compute(cr, uid, pricelist_obj.browse(cr, uid, pricelist_id).currency_id.id, currency_id, price)
else:
price = 0
sellers_price += '%.2f' % price + '\r\n'
price = supplier_info_pool.price_get(cr, uid, seller_id.name.id, prod.id, number*prod_qtty)[seller_id.name.id]
price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, price, to_uom_id=product_uom.id)
sellers_price += str(price) + '\r\n'
xml += "<col para='yes'>" + prod_name + '</col>'
xml += "<col para='no'>" + main_sp_name + sellers + '</col>'
xml += "<col para='yes'>" + str(prod_qtty) + '</col>'
xml += "<col para='yes'>" + prod_uom + '</col>'
xml += "<col para='yes'>" + product_uom.name + '</col>'
xml += "<col para='yes'>" + main_strd_price + '</col>'
xml += "<col para='no'>" + main_sp_price + sellers_price + '</col>'
@@ -88,9 +81,9 @@ class report_custom(report_rml):
def process_workcenter(wrk):
xml = '<row>'
workcenter = pooler.get_pool(cr.dbname).get('mrp.workcenter').browse(cr, uid, wrk['workcenter_id'])
workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id'])
xml += "<col para='yes'>" + wrk['name'] + '</col>'
xml += "<col para='yes'>" + workcenter.name + '</col>'
xml += "<col para='yes'>" + '</col>'
xml += "<col para='no'>" + '</col>'
xml += "<col/>"
@@ -150,22 +143,23 @@ class report_custom(report_rml):
</lines>
""" % (_('Product name'), _('Product supplier'), _('Product Quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
company_currency = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id.currency_id.id
company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id.id
first = True
for prod_id in ids:
bom_ids = pooler.get_pool(cr.dbname).get('mrp.bom').search(cr, uid, [('product_id','=',prod_id)])
prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, prod_id)
for bom_id in bom_ids:
bom = pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_id)
sub_boms = pooler.get_pool(cr.dbname).get('mrp.bom')._bom_explode(cr, uid, bom, number, [])
for product in product_pool.browse(cr, uid, ids, context=context):
bom_ids = bom_pool.search(cr, uid, [('product_id','=',product.id)])
for bom in bom_pool.browse(cr, uid, bom_ids, context=context):
sub_boms = bom_pool._bom_explode(cr, uid, bom, number, [])
total = 0
total_strd = 0
parent_bom = {'product_qty': bom.product_qty, 'name': bom.product_id.name, 'product_uom': bom.product_id.uom_id.factor, 'product_id': bom.product_id.id}
parent_bom = {
'product_qty': bom.product_qty,
'name': bom.product_id.name,
'product_uom': bom.product_uom.id,
'product_id': bom.product_id.id
}
xml_tmp = ''
for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
txt, sum, sum_strd = process_bom(sub_bom, company_currency)
txt, sum, sum_strd = process_bom(sub_bom, company_currency, factor=1/bom.product_qty)
xml_tmp += txt
total += sum
total_strd += sum_strd
@@ -187,7 +181,7 @@ class report_custom(report_rml):
first = False
xml = '<?xml version="1.0" ?><report>' + config_start + '<report-header>%s\n\r' % (_('Product Cost Structure')) + prod.name + '</report-header>'+ config_stop + header + xml + '</report>'
xml = '<?xml version="1.0" ?><report>' + config_start + '<report-header>%s\n\r' % (_('Product Cost Structure')) + product.name + '</report-header>'+ config_stop + header + xml + '</report>'
return xml
+3
View File
@@ -27,6 +27,9 @@ class mrp_price(osv.osv_memory):
_columns = {
'number': fields.integer('Quantity', required=True, help="Specify quantity of products to produce. Report of Cost structure will be displayed base on this qunatity."),
}
_defaults = {
'number': 1,
}
def print_report(self, cr, uid, ids, context=None):
""" To print the report of Product cost structure
+1 -1
View File
@@ -18,7 +18,7 @@
<button icon='gtk-close' special="cancel"
string="Close" />
<button name="print_report" string="Print"
colspan="1" type="object" icon="gtk-ok" />
colspan="1" type="object" icon="gtk-print" />
</group>
</form>
</field>
+1 -2
View File
@@ -291,8 +291,7 @@ class procurement_order(osv.osv):
if not procurement.product_id.seller_ids:
cr.execute('update procurement_order set message=%s where id=%s', (_('No supplier defined for this product !'), procurement.id))
return False
partner_list = sorted([(partner_id.sequence, partner_id) for partner_id in procurement.product_id.seller_ids if partner_id and partner_id.sequence])
partner = partner_list and partner_list[0] and partner_list[0][1] and partner_list[0][1].name or False
partner = procurement.product_id.seller_id #Taken Main Supplier of Product of Procurement.
if user.company_id and user.company_id.partner_id:
if partner.id == user.company_id.partner_id.id:
+53 -7
View File
@@ -59,7 +59,7 @@ class product_uom(osv.osv):
def _factor_inv_write(self, cursor, user, id, name, value, arg, context):
return self.write(cursor, user, id, {'factor': self._compute_factor_inv(value)}, context=context)
def create(self, cr, uid, data, context={}):
if 'factor_inv' in data:
if data['factor_inv'] <> 1:
@@ -180,7 +180,7 @@ class product_category(osv.osv):
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type'),
}
_defaults = {
'type' : lambda *a : 'normal',
@@ -212,14 +212,18 @@ product_category()
class product_template(osv.osv):
_name = "product.template"
_description = "Product Template"
def _calc_seller_delay(self, cr, uid, ids, name, arg, context={}):
def _calc_seller(self, cr, uid, ids, fields, arg, context={}):
result = {}
for product in self.browse(cr, uid, ids, context):
for field in fields:
result[product.id] = {field:False}
result[product.id]['seller_delay'] = 1
if product.seller_ids:
partner_list = sorted([(partner_id.sequence, partner_id) for partner_id in product.seller_ids if partner_id and partner_id.sequence])
result[product.id] = partner_list and partner_list[0] and partner_list[0][1] and partner_list[0][1].delay or False
else:
result[product.id] = 1
main_supplier = partner_list and partner_list[0] and partner_list[0][1] or False
result[product.id]['seller_delay'] = main_supplier and main_supplier.delay or 1
result[product.id]['seller_qty'] = main_supplier and main_supplier.qty or 0.0
result[product.id]['seller_id'] = main_supplier and main_supplier.name.id or False
return result
_columns = {
@@ -254,7 +258,9 @@ class product_template(osv.osv):
help='Coefficient to convert UOM to UOS\n'
' uos = uom * coeff'),
'mes_type': fields.selection((('fixed', 'Fixed'), ('variable', 'Variable')), 'Measure Type', required=True),
'seller_delay': fields.function(_calc_seller_delay, method=True, type='integer', string='Supplier Lead Time', help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."),
'seller_delay': fields.function(_calc_seller, method=True, type='integer', string='Supplier Lead Time', multi="seller_delay", help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."),
'seller_qty': fields.function(_calc_seller, method=True, type='float', string='Supplier Quantity', multi="seller_qty", help="This is minimum quantity to purchase from Main Supplier."),
'seller_id': fields.function(_calc_seller, method=True, type='many2one', relation="res.partner", string='Main Supplier', help="Main Supplier who has highest priority in Supplier List.", multi="seller_id"),
'seller_ids': fields.one2many('product.supplierinfo', 'product_id', 'Partners'),
'loc_rack': fields.char('Rack', size=16),
'loc_row': fields.char('Row', size=16),
@@ -633,6 +639,46 @@ class product_supplierinfo(osv.osv):
'delay': lambda *a: 1,
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.supplierinfo', context=c)
}
def price_get(self, cr, uid, supplier_ids, product_id, product_qty=1, context=None):
"""
Calculate price from supplier pricelist.
@param supplier_ids: Ids of res.partner object.
@param product_id: Id of product.
@param product_qty: specify quantity to purchase.
"""
if not context:
context = {}
if type(supplier_ids) in (int,long,):
supplier_ids = [supplier_ids]
res = {}
product_pool = self.pool.get('product.product')
partner_pool = self.pool.get('res.partner')
pricelist_pool = self.pool.get('product.pricelist')
currency_pool = self.pool.get('res.currency')
currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
for supplier in partner_pool.browse(cr, uid, supplier_ids, context=context):
# Compute price from standard price of product
price = product_pool.price_get(cr, uid, [product_id], 'standard_price')[product_id]
# Compute price from Purchase pricelist of supplier
pricelist_id = supplier.property_product_pricelist_purchase.id
if pricelist_id:
price = pricelist_pool.price_get(cr, uid, [pricelist_id], product_id, product_qty).setdefault(pricelist_id, 0)
price = currency_pool.compute(cr, uid, pricelist_pool.browse(cr, uid, pricelist_id).currency_id.id, currency_id, price)
# Compute price from supplier pricelist which are in Supplier Information
supplier_info_ids = self.search(cr, uid, [('name','=',supplier.id),('product_id','=',product_id)])
if supplier_info_ids:
cr.execute('SELECT * ' \
'FROM pricelist_partnerinfo ' \
'WHERE suppinfo_id IN %s' \
'AND min_quantity <= %s ' \
'ORDER BY min_quantity DESC LIMIT 1', (tuple(supplier_info_ids),product_qty,))
res2 = cr.dictfetchone()
if res2:
price = res2['price']
res[supplier.id] = price
return res
_order = 'sequence'
product_supplierinfo()
+2
View File
@@ -149,6 +149,8 @@
<newline/>
<field groups="base.group_extended" name="cost_method"/>
<newline/>
<field groups="base.group_extended" name="seller_id"/>
<newline/>
<field colspan="4" name="seller_ids" nolabel="1"/>
</page>
<page string="Descriptions">
+1 -1
View File
@@ -23,7 +23,7 @@ import time
from report import report_sxw
from osv import osv
import pooler
from tools.translate import _
class product_pricelist(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(product_pricelist, self).__init__(cr, uid, name, context=context)
+3 -7
View File
@@ -44,18 +44,14 @@ class product_price_list(osv.osv_memory):
}
def print_report(self, cr, uid, ids, context=None):
"""
To get the date and print the report
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return : return report
To get the date and print the report
@return : return report
"""
datas = {'ids': context.get('active_ids', [])}
res = self.read(cr, uid, ids, ['price_list','qty1', 'qty2','qty3','qty4','qty5'], context)
res = res and res[0] or {}
price_dict = self.pool.get('product.pricelist').price_get(cr, uid, [res['price_list']], 1, 1.0)
datas['form'] = res
return {
'type': 'ir.actions.report.xml',
+8 -5
View File
@@ -5,11 +5,12 @@
<!-- Product Price List -->
<record id="view_product_price_list" model="ir.ui.view">
<field name="name">Price List</field>
<field name="name">Price per unit</field>
<field name="model">product.price_list</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Price list">
<form string="Price per Unit">
<separator colspan="4" string="Calculate Product Price per unit base on pricelist version."/>
<field name="price_list" widget="selection"/>
<field name="qty1" colspan="2" />
<field name="qty2" colspan="2" />
@@ -19,15 +20,17 @@
<separator colspan="4"/>
<group col="2" colspan="4">
<button icon="gtk-cancel" special="cancel" string="Close"/>
<button name="print_report" string="Print Report" type="object" icon="gtk-print"/>
<button name="print_report" string="Print" type="object" icon="gtk-print"/>
</group>
</form>
</field>
</record>
<act_window id="action_product_price_list"
key2="client_action_multi" name="Price List"
res_model="product.price_list" src_model="product.product"
key2="client_print_multi"
name="Price Per Unit"
res_model="product.price_list"
src_model="product.product"
view_mode="form" target="new" view_type="form" />
</data>
+8 -7
View File
@@ -305,7 +305,7 @@ class purchase_order(osv.osv):
def inv_line_create(self, cr, uid, a, ol):
return (0, False, {
'name': ol.name,
'account_id': a.id,
'account_id': a,
'price_unit': ol.price_unit or 0.0,
'quantity': ol.product_qty,
'product_id': ol.product_id.id or False,
@@ -344,7 +344,7 @@ class purchase_order(osv.osv):
if not a:
raise osv.except_osv(_('Error !'), _('There is no expense account defined for this product: "%s" (id:%d)') % (ol.product_id.name, ol.product_id.id,))
else:
a = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category')
a = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category').id
fpos = o.fiscal_position or False
a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
il.append(self.inv_line_create(cr, uid, a, ol))
@@ -746,23 +746,24 @@ class procurement_order(osv.osv):
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 = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
seller_qty = procurement.product_id.seller_qty
seller_delay = int(procurement.product_id.seller_delay)
partner_id = partner.id
partner_rec = procurement.product_id.seller_ids[0]
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,partner_rec.qty)
if seller_qty:
qty = max(qty,seller_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 - partner_rec.delay
newdate = newdate - seller_delay
#Passing partner_id to context for purchase order line integrity of Line name
context.update({'lang': partner.lang, 'partner_id': partner_id})
+1 -2
View File
@@ -78,8 +78,7 @@
<field name="name" select="1"/>
<field name="manager" select="1"/>
<field name="company_id" select="1" groups="base.group_multi_company"/>
<newline/>
<field colspan="4" name="week_id" nolabel="1" widget="one2many_list"/>
<!-- <field colspan="4" name="week_id" nolabel="1" widget="one2many_list"/>-->
</form>
</field>
</record>
+4 -3
View File
@@ -2079,9 +2079,10 @@ class stock_move(osv.osv):
self.write(cr, uid, [move.id], update_val)
product_obj = self.pool.get('product.product')
for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]):
message = _('Product ') + " '" + name + "' "+ _("is consumed with") + " '" + str(move.product_qty) + "' "+ _("quantity.")
self.log(cr, uid, move.id, message)
for new_move in self.browse(cr, uid, res, context=context):
for (id, name) in product_obj.name_get(cr, uid, [new_move.product_id.id]):
message = _('Product ') + " '" + name + "' "+ _("is consumed with") + " '" + str(new_move.product_qty) + "' "+ _("quantity.")
self.log(cr, uid, new_move.id, message)
self.action_done(cr, uid, res)
return res