bzr revid: fp@tinyerp.com-20081112054334-8ed7ex6bup5izvmf
This commit is contained in:
Fabien Pinckaers 2008-11-12 06:43:34 +01:00
commit de61e9e960
8 changed files with 306 additions and 74 deletions

View File

@ -718,9 +718,15 @@ class account_invoice(osv.osv):
line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
if 'account_analytic_id' in line:
line['account_analytic_id'] = line.get('account_analytic_id', False) and line['account_analytic_id'][0]
if 'tax_code_id' in line :
if isinstance(line['tax_code_id'],tuple) and len(line['tax_code_id']) >0 :
line['tax_code_id'] = line['tax_code_id'][0]
if 'base_code_id' in line :
if isinstance(line['base_code_id'],tuple) and len(line['base_code_id']) >0 :
line['base_code_id'] = line['base_code_id'][0]
return map(lambda x: (0,0,x), lines)
def refund(self, cr, uid, ids):
def refund(self, cr, uid, ids, date=None, period_id=None, description=None):
invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id'])
new_ids = []
@ -741,21 +747,28 @@ class account_invoice(osv.osv):
tax_lines = self.pool.get('account.invoice.tax').read(cr, uid, invoice['tax_line'])
tax_lines = filter(lambda l: l['manual'], tax_lines)
tax_lines = self._refund_cleanup_lines(tax_lines)
if not date :
date = time.strftime('%Y-%m-%d')
invoice.update({
'type': type_dict[invoice['type']],
'date_invoice': time.strftime('%Y-%m-%d'),
'date_invoice': date,
'state': 'draft',
'number': False,
'invoice_line': invoice_lines,
'tax_line': tax_lines
})
if period_id :
invoice.update({
'period_id': period_id,
})
if description :
invoice.update({
'name': description,
})
# take the id part of the tuple returned for many2one fields
for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
'account_id', 'currency_id', 'payment_term', 'journal_id'):
invoice[field] = invoice[field] and invoice[field][0]
# create the new invoice
new_ids.append(self.create(cr, uid, invoice))
return new_ids

View File

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@ -19,44 +19,206 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import pooler
import osv
import netsvc
import time
sur_form = '''<?xml version="1.0"?>
<form string="Credit Note">
<label string="Are you sure you want to refund this invoice ?"/>
<label string="Are you sure you want to refund this invoice ?" colspan="2"/>
<newline />
<field name="date" />
<field name="period" />
<field name="description" width="150" />
</form>'''
sur_fields = {
}
'date': {'string':'Operation date','type':'date', 'required':'False'},
'period':{'string': 'Force period', 'type': 'many2one',
'relation': 'account.period', 'required': False},
'description':{'string':'Description', 'type':'char', 'required':'True'},
}
class wiz_refund(wizard.interface):
def _invoice_refund(self, cr, uid, data, context):
return self._compute_refund(cr, uid, data, 'refund', context)
def _invoice_cancel(self, cr, uid, data, context):
return self._compute_refund(cr, uid, data, 'cancel', context)
def _invoice_modify(self, cr, uid, data, context):
return self._compute_refund(cr, uid, data, 'modify', context)
def _compute_refund(self, cr, uid, data, mode, context):
form = data['form']
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.invoice').refund(cr, uid, data['ids'])
return {
'domain': "[('id','in', ["+','.join(map(str,ids))+"])]",
'name': 'Invoices',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'view_id': False,
'context': "{'type':'out_refund'}",
'type': 'ir.actions.act_window'
}
reconcile_obj = pool.get('account.move.reconcile')
account_m_line_obj = pool.get('account.move.line')
created_inv = []
date = False
period = False
description = False
for inv in pool.get('account.invoice').browse(cr, uid, data['ids']) :
if form['period'] :
period = form['period']
else:
period = inv.period_id.id
if form['date'] :
date = form['date']
if not form['period'] :
try :
#we try in multy company mode
cr.execute("""SELECT id
from account_period where date('%s')
between date_start AND date_stop and company_id = %s limit 1 """%(
form['date'],
pool.get('res.users').browse(cr,uid,uid).company_id.id
)
)
except :
#we try in mono company mode
cr.execute("""SELECT id
from account_period where date('%s')
between date_start AND date_stop limit 1 """%(
form['date'],
)
)
res = cr.fetchone()
if res:
period = res[0]
else:
date = inv.date_invoice
if form['description'] :
description = form['description']
else:
description = inv.name
refund_id = pool.get('account.invoice').refund(cr, uid, [inv.id],date, period, description)
refund = pool.get('account.invoice').browse(cr, uid, refund_id[0])
# we compute due date
#!!!due date = date inv date on formdate
pool.get('account.invoice').write(cr, uid, [refund.id],{'date_due':date,'check_total':inv.check_total})
created_inv.append(refund_id[0])
#if inv is paid we unreconcile
if mode in ('cancel','modify'):
movelines = inv.move_id.line_id
#we unreconcile the lines
to_reconcile_ids = {}
for line in movelines :
#if the account of the line is the as the one in the invoice
#we reconcile
if line.account_id.id == inv.account_id.id :
to_reconcile_ids[line.account_id.id] =[line.id]
if type(line.reconcile_id) != osv.orm.browse_null :
reconcile_obj.unlink(cr,uid, line.reconcile_id.id)
#we advance the workflow of the refund to open
wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid, 'account.invoice', refund.id, 'invoice_open', cr)
#we reload the browse record
refund = pool.get('account.invoice').browse(cr, uid, refund_id[0])
#we match the line to reconcile
for tmpline in refund.move_id.line_id :
if tmpline.account_id.id == inv.account_id.id :
to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
for account in to_reconcile_ids :
account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
writeoff_period_id=period,
writeoff_journal_id=inv.journal_id.id,
writeoff_acc_id=inv.account_id.id
)
#we create a new invoice that is the copy of the original
if mode == 'modify' :
invoice = pool.get('account.invoice').read(cr, uid, [inv.id],
['name', 'type', 'number', 'reference',
'comment', 'date_due', 'partner_id', 'address_contact_id',
'address_invoice_id', 'partner_insite','partner_contact',
'partner_ref', 'payment_term', 'account_id', 'currency_id',
'invoice_line', 'tax_line', 'journal_id','period_id'
]
)
invoice = invoice[0]
del invoice['id']
invoice_lines = pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line'])
invoice_lines = pool.get('account.invoice')._refund_cleanup_lines(invoice_lines)
tax_lines = pool.get('account.invoice.tax').read(
cr, uid, invoice['tax_line'])
tax_lines = pool.get('account.invoice')._refund_cleanup_lines(tax_lines)
invoice.update({
'type': inv.type,
'date_invoice': date,
'state': 'draft',
'number': False,
'invoice_line': invoice_lines,
'tax_line': tax_lines,
'period_id': period,
'name':description
})
#take the id part of the tuple returned for many2one fields
for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
'account_id', 'currency_id', 'payment_term', 'journal_id'):
invoice[field] = invoice[field] and invoice[field][0]
# create the new invoice
inv_id = pool.get('account.invoice').create(cr, uid, invoice,{})
# we compute due date
if inv.payment_term.id:
data = pool.get('account.invoice').onchange_payment_term_date_invoice(cr, uid, [inv_id],inv.payment_term.id,date)
if 'value' in data and data['value']:
pool.get('account.invoice').write(cr, uid, [inv_id],data['value'])
created_inv.append(inv_id)
#we get the view id
mod_obj = pool.get('ir.model.data')
act_obj = pool.get('ir.actions.act_window')
if inv.type == 'out_invoice':
xml_id = 'action_invoice_tree5'
elif inv.type == 'in_invoice':
xml_id = 'action_invoice_tree8'
elif type == 'out_refund':
xml_id = 'action_invoice_tree10'
else:
xml_id = 'action_invoice_tree12'
#we get the model
result = mod_obj._get_id(cr, uid, 'account', xml_id)
id = mod_obj.read(cr, uid, result, ['res_id'])['res_id']
# we read the act window
result = act_obj.read(cr, uid, id)
result['res_id'] = created_inv
return result
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':sur_form, 'fields':sur_fields, 'state':[('end','Cancel'),('refund','Credit Note')]}
'result': {'type':'form', 'arch':sur_form, 'fields':sur_fields, 'state':[('end','Cancel'),('refund','Refund Invoice'),('cancel_invoice','Cancel Invoice'),('modify_invoice','Modify Invoice')]}
},
'refund': {
'actions': [],
'result': {'type':'action', 'action':_invoice_refund, 'state':'end'}
}
'result': {'type':'action', 'action':_invoice_refund, 'state':'end'},
},
'cancel_invoice': {
'actions': [],
'result': {'type':'action', 'action':_invoice_cancel, 'state':'end'},
},
'modify_invoice': {
'actions': [],
'result': {'type':'action', 'action':_invoice_modify, 'state':'end'},
},
}
wiz_refund('account.invoice.refund')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@ -70,6 +70,7 @@ theme.default_font_family = "Helvetica-Bold"
theme.default_font_size = 18
theme.default_line_width = 1.0
import tools
import os
parents = {
@ -86,11 +87,13 @@ class accounting_report_indicator(report_sxw.rml_parse):
self.ret_list = []
self.localcontext.update({
'time': time,
'test': self.test1,
'getgraph': self.getgraph,
'lines':self.lines,
'getarray':self.getarray,
'gettree':self.gettree,
})
self.count=0
self.treecount=0
self.list=[]
self.header_name=self.header_val=[]
@ -166,6 +169,7 @@ class accounting_report_indicator(report_sxw.rml_parse):
'code':obj_ind.code,
'expression':obj_ind.expression,
'disp_graph':obj_ind.disp_graph,
'disp_tree':obj_ind.disp_tree,
'note':obj_ind.note,
'type':obj_ind.type,
}
@ -175,7 +179,7 @@ class accounting_report_indicator(report_sxw.rml_parse):
def getarray(self,data,object):
res={}
result=[]
self.test1(data,object,intercall=True)
self.getgraph(data,object,intercall=True)
self.header_val=[str(x) for x in self.header_val]
temp_dict=zip(self.header_name,self.header_val)
res=dict(temp_dict)
@ -183,8 +187,56 @@ class accounting_report_indicator(report_sxw.rml_parse):
result.append(res)
return result
def gettree(self,data,object):
pool_history=self.pool.get('account.report.report')
obj_history=pool_history.browse(self.cr,self.uid,object['id'])
result=[]
self.treecount +=1
path=tools.config['addons_path']+"/account_report/tmp_images/tree_image"
def test1(self,data,object,intercall=False):
dirname =tools.config['addons_path']+'/account_report/tmp_images/'
if not os.path.isdir(dirname):
os.mkdir(dirname)
can = canvas.init('tree_image'+str(self.treecount)+".png")
theme.default_font_size = 12
tb = text_box.T(loc=(0,500),line_style=line_style.darkblue,text=str(obj_history.name))
tb.add_arrow((100, 500))
tb.draw()
base_x=100
base_y=500
if obj_history.child_ids:
can.line(line_style.black,base_x-30,base_y,base_x-30,base_y-(50*(len(obj_history.child_ids)-1)))
self.base_x=1
def draw_tree(obj_his,base_x,base_y):
for i in range(len(obj_his.child_ids)):
# print obj_his.name,base_x,base_y
if i<>0:
a = arrow.T(head_style = 1)
a.draw([(base_x-(30),base_y-(50*(i))), (base_x,base_y-(50*(i)))])
tb12 = text_box.T(loc=(base_x,base_y-(50*(i))), text=str(obj_his.child_ids[i].name))
tb12.draw()
# base_x=base_x+(100*self.base_x)
# base_y=base_y-(50*(i))
for j in obj_his.child_ids[i].child_ids:
# print j
# tb12.add_arrow((base_x,base_y))
# tb12.draw()
can.line(line_style.black,base_x-30+100,base_y-(50*(i)),base_x-30+100,base_y-(50*(len(obj_his.child_ids)-1)))
draw_tree(j,base_x+100,base_y-(50*(i)))
draw_tree(obj_history,base_x,base_y)
can.close()
os.system('cp '+'tree_image'+str(self.treecount)+'.png ' +path+str(self.treecount)+'.png')
os.system('rm '+'tree_image'+str(self.treecount)+'.png')
return path+str(self.treecount)+'.png'
def getgraph(self,data,object,intercall=False):
obj_history=self.pool.get('account.report.history')
if data['select_base']=='year':

View File

@ -120,7 +120,8 @@
<para style="P3">
<font color="white"> </font>
</para>
<para style="P1">[[ o['disp_graph'] and setTag('para','image',{'width':'450.00','height':'215.00','file':test(data['form'],o)}) or removeParentNode('para') ]]</para>
<para style="P1">[[ o['disp_tree'] and setTag('para','image',{'file':gettree(data['form'],o)}) or removeParentNode('para') ]]</para>
<para style="P1">[[ o['disp_graph'] and setTag('para','image',{'width':'450.00','height':'215.00','file':getgraph(data['form'],o)}) or removeParentNode('para') ]]</para>
<para style="P3">
<font color="white"> </font>
</para>

View File

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@ -74,28 +74,29 @@ class node_class(object):
if self.object2:
where.append( ('res_model','=',self.object2._name) )
where.append( ('res_id','=',self.object2.id) )
for content in self.object.content_ids:
if self.object2 or not content.include_name:
if content.include_name:
test_nodename = self.object2.name + (content.suffix or '') + (content.extension or '')
else:
test_nodename = (content.suffix or '') + (content.extension or '')
if test_nodename.find('/'):
test_nodename=test_nodename.replace('/', '_')
path = self.path+'/'+test_nodename
#path = self.path+'/'+self.object2.name + (content.suffix or '') + (content.extension or '')
if not nodename:
n = node_class(self.cr, self.uid,path, self.object2, False, content=content, type='content', root=False)
res2.append( n)
else:
if nodename == test_nodename:
n = node_class(self.cr, self.uid, path, self.object2, False, content=content, type='content', root=False)
res2.append(n)
for content in self.object.content_ids:
if self.object2 or not content.include_name:
if content.include_name:
test_nodename = self.object2.name + (content.suffix or '') + (content.extension or '')
else:
test_nodename = (content.suffix or '') + (content.extension or '')
if test_nodename.find('/'):
test_nodename=test_nodename.replace('/', '_')
path = self.path+'/'+test_nodename
#path = self.path+'/'+self.object2.name + (content.suffix or '') + (content.extension or '')
if not nodename:
n = node_class(self.cr, self.uid,path, self.object2, False, content=content, type='content', root=False)
res2.append( n)
else:
if nodename == test_nodename:
n = node_class(self.cr, self.uid, path, self.object2, False, content=content, type='content', root=False)
res2.append(n)
else:
where.append( ('parent_id','=',self.object.id) )
where.append( ('res_id','=',False) )
if nodename:
where.append( (fobj._rec_name,'=',nodename) )
print where+[ ('parent_id','=',self.object and self.object.id or False) ]
ids = fobj.search(self.cr, self.uid, where+[ ('parent_id','=',self.object and self.object.id or False) ], context=self.context)
if self.object and self.root and (self.object.type=='ressource'):
ids += fobj.search(self.cr, self.uid, where+[ ('parent_id','=',False) ], context=self.context)
@ -560,6 +561,7 @@ class document_file(osv.osv):
if not self._check_duplication(cr,uid,vals):
raise except_orm('ValidateError', 'File name must be unique!')
result = super(document_file,self).write(cr,uid,ids,vals,context=context)
cr.commit()
try:
for f in self.browse(cr, uid, ids, context=context):
if 'datas' not in vals:
@ -568,6 +570,7 @@ class document_file(osv.osv):
super(document_file,self).write(cr, uid, ids, {
'index_content': res
})
cr.commit()
except:
pass
return result

View File

@ -15,15 +15,15 @@
<frame id="col1" x1="2.0cm" y1="2.5cm" width="24.7cm" height="17cm"/>
</pageTemplate>
</template>
<stylesheet>
<paraStyle name="normal" fontName="Helvetica" fontSize="6" alignment="center" />
<paraStyle name="normal" fontName="Helvetica" fontSize="6" alignment="left" />
<paraStyle name="normal-title" fontName="Helvetica" fontSize="6" />
<paraStyle name="title" fontName="Helvetica" fontSize="18" alignment="center" />
<paraStyle name="employee" fontName="Helvetica-Oblique" fontSize="10" textColor="blue" />
<paraStyle name="glande" textColor="red" />
<paraStyle name="normal_people" textColor="green" />
<paraStyle name="esclave" textColor="purple" />
<paraStyle name="glande" textColor="red" fontSize="7" fontName="Helvetica"/>
<paraStyle name="normal_people" textColor="green" fontSize="7" fontName="Helvetica"/>
<paraStyle name="esclave" textColor="purple" fontSize="7" fontName="Helvetica"/>
<blockTableStyle id="month">
<blockAlignment value="CENTER" start="1,0" stop="-1,-1" />
<blockFont name="Helvetica" size="8" start="0,0" stop="-1,1"/>
@ -90,7 +90,7 @@
<xsl:for-each select="report/days/day">
<xsl:variable name="today" select="attribute::number" />
<td>
<para>
<para style="normal">
<xsl:choose>
<xsl:when test="sum(//time-element[@date=$today]) &lt; 7.5">
<xsl:attribute name="style">glande</xsl:attribute>
@ -102,12 +102,12 @@
<xsl:attribute name="style">esclave</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="sum(//time-element[@date=$today])" />
<xsl:value-of select="format-number(sum(//time-element[@date=$today]),'##.##')" />
</para>
</td>
</xsl:for-each>
<td>
<xsl:value-of select="sum(//time-element)" />
<xsl:value-of select="format-number(sum(//time-element),'##.##')" />
</td>
</tr>
</blockTable>
@ -115,6 +115,7 @@
<xsl:template match="account">
<xsl:variable name="aid" select="attribute::id" />
<tr>
<td>
<para style="normal-title"><xsl:value-of select="attribute::name" /></para>
@ -126,8 +127,8 @@
</td>
</xsl:for-each>
<td>
<para style="normal"><xsl:value-of select="sum(//account[@id=$aid]/time-element)" /></para>
<para style="normal"><xsl:value-of select="format-number(sum(//account[@id=$aid]/time-element),'##.##')" /></para>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

View File

@ -15,15 +15,15 @@
<frame id="col1" x1="2.0cm" y1="2.5cm" width="24.7cm" height="17cm"/>
</pageTemplate>
</template>
<stylesheet>
<paraStyle name="normal" fontName="Helvetica" fontSize="6" alignment="center" />
<paraStyle name="normal-title" fontName="Helvetica" fontSize="6" />
<paraStyle name="title" fontName="Helvetica" fontSize="18" alignment="center" />
<paraStyle name="employee" fontName="Helvetica-Oblique" fontSize="10" textColor="blue" />
<paraStyle name="glande" textColor="red" />
<paraStyle name="normal_people" textColor="green" />
<paraStyle name="esclave" textColor="purple" />
<paraStyle name="glande" textColor="red" fontSize="7" fontName="Helvetica"/>
<paraStyle name="normal_people" textColor="green" fontSize="7" fontName="Helvetica"/>
<paraStyle name="esclave" textColor="purple" fontSize="7" fontName="Helvetica"/>
<blockTableStyle id="month">
<blockAlignment value="CENTER" start="1,0" stop="-1,-1" />
<blockFont name="Helvetica" size="8" start="0,0" stop="-1,1"/>
@ -102,12 +102,12 @@
<xsl:attribute name="style">esclave</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="format-number(//employee[@id=$id]/time-element[@date=$today], '#.#')" />
<xsl:value-of select="format-number(//employee[@id=$id]/time-element[@date=$today], '##.##')" />
</para>
</td>
</xsl:for-each>
<td>
<xsl:value-of select="sum(//employee[@id=$id]/time-element)"/>
<xsl:value-of select="format-number(sum(//employee[@id=$id]/time-element),'##.##')"/>
</td>
</tr>
</xsl:for-each>
@ -115,10 +115,10 @@
<td>Total</td>
<xsl:for-each select="report/days/day">
<xsl:variable name="today" select="attribute::number"/>
<td t="1"><xsl:value-of select="sum(//time-element[@date=$today])"/></td>
<td t="1"><xsl:value-of select="format-number(sum(//time-element[@date=$today]),'##.##')"/></td>
</xsl:for-each>
<td t="1"><xsl:value-of select="sum(//time-element)"/></td>
<td t="1"><xsl:value-of select="format-number(sum(//time-element),'##.##')"/></td>
</tr>
</blockTable>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report auto="False" id="report_product_history" model="product.product" name="stock.product.history" string="Futur Stock Forecast"/>
<report auto="False" id="report_product_history" model="product.product" name="stock.product.history" string="Future Stock Forecast"/>
<!-- <report id="report_picking_list" model="stock.picking" name="stock.picking.list" string="Packing list" xml="stock/report/picking.xml" xsl="stock/report/picking.xsl"/>-->
<report id="report_picking_list" model="stock.picking" name="stock.picking.list" string="Packing list" rml="stock/report/picking.rml"/>
<report id="report_move_labels" model="stock.move" name="stock.move.label" string="Print Item Labels" xml="stock/report/lot_move_label.xml" xsl="stock/report/lot_move_label.xsl"/>
<report id="report_location_overview" model="stock.location" name="stock.location.overview" string="Location Overview" xml="stock/report/lot_overview.xml" xsl="stock/report/lot_overview.xsl"/>
<report auto="False" id="report_lot_location" model="stock.location" name="lot.location" rml="stock/report/lot_location.rml" string="Lots by location"/>
<report id="report_location_overview_all" model="stock.location" name="stock.location.overview.all" string="Location Content (With childs)" xml="stock/report/lot_overview_all.xml" xsl="stock/report/lot_overview_all.xsl"/>
</data>
</openerp>