V11 : more explicit logs \nDTA: History
bzr revid: pinky-32cbe8b6df3c8c2d517a74732463c9b180e46caa
This commit is contained in:
parent
1dc7c7210f
commit
180ce7de23
|
@ -36,18 +36,6 @@ from tools.misc import currency
|
||||||
import mx.DateTime
|
import mx.DateTime
|
||||||
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
|
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
|
||||||
|
|
||||||
class account_cash_discount(osv.osv):
|
|
||||||
_name = "account.cash.discount"
|
|
||||||
_description = "Cash Discount" #A reduction in the price of an item for sale allowed if payment is made within a stipulated period.
|
|
||||||
_columns = {
|
|
||||||
'name': fields.char('Name', size=32),
|
|
||||||
'date': fields.date('Date', required=True),
|
|
||||||
'discount': fields.float('Discount (%)', digits=(16,2)),
|
|
||||||
'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
|
|
||||||
}
|
|
||||||
account_cash_discount()
|
|
||||||
|
|
||||||
|
|
||||||
class account_payment_term(osv.osv):
|
class account_payment_term(osv.osv):
|
||||||
_name = "account.payment.term"
|
_name = "account.payment.term"
|
||||||
_description = "Payment Term"
|
_description = "Payment Term"
|
||||||
|
@ -56,7 +44,7 @@ class account_payment_term(osv.osv):
|
||||||
'active': fields.boolean('Active'),
|
'active': fields.boolean('Active'),
|
||||||
'note': fields.text('Description'),
|
'note': fields.text('Description'),
|
||||||
'line_ids': fields.one2many('account.payment.term.line', 'payment_id', 'Terms'),
|
'line_ids': fields.one2many('account.payment.term.line', 'payment_id', 'Terms'),
|
||||||
'cash_discount_ids': fields.one2many('account.cash.discount', 'payment_id', 'Cash Discount'),
|
'cash_discount_ids': fields.one2many('account.cash.discount', 'payment_id', 'Cash Discounts'),
|
||||||
}
|
}
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'active': lambda *a: 1,
|
'active': lambda *a: 1,
|
||||||
|
@ -105,6 +93,18 @@ class account_payment_term_line(osv.osv):
|
||||||
account_payment_term_line()
|
account_payment_term_line()
|
||||||
|
|
||||||
|
|
||||||
|
class account_cash_discount(osv.osv):
|
||||||
|
_name = "account.cash.discount"
|
||||||
|
_description = "Cash Discount" #A reduction in the price if payment is made within a stipulated period.
|
||||||
|
_columns = {
|
||||||
|
'name': fields.char('Name', size=32),
|
||||||
|
'date': fields.date('Date', required=True),
|
||||||
|
'discount': fields.float('Discount (%)',required=True),
|
||||||
|
'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
|
||||||
|
}
|
||||||
|
account_cash_discount()
|
||||||
|
|
||||||
|
|
||||||
class account_account_type(osv.osv):
|
class account_account_type(osv.osv):
|
||||||
_name = "account.account.type"
|
_name = "account.account.type"
|
||||||
_description = "Account Type"
|
_description = "Account Type"
|
||||||
|
|
|
@ -137,7 +137,7 @@
|
||||||
<field name="project_id"/>
|
<field name="project_id"/>
|
||||||
|
|
||||||
<field name="payment_term"/>
|
<field name="payment_term"/>
|
||||||
<field name="date_due"/>
|
<field name="date_due" select="1"/>
|
||||||
|
|
||||||
<field name="journal_id" select="1"/>
|
<field name="journal_id" select="1"/>
|
||||||
|
|
||||||
|
|
|
@ -507,7 +507,6 @@ class account_invoice_line(osv.osv):
|
||||||
if partner_id:
|
if partner_id:
|
||||||
lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang']
|
lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang']
|
||||||
context={'lang': lang}
|
context={'lang': lang}
|
||||||
print context
|
|
||||||
res = self.pool.get('product.product').browse(cr, uid, product, context=context)
|
res = self.pool.get('product.product').browse(cr, uid, product, context=context)
|
||||||
result = {'price_unit': res.list_price, 'invoice_line_tax_id':map(lambda x: x.id, res.taxes_id)}
|
result = {'price_unit': res.list_price, 'invoice_line_tax_id':map(lambda x: x.id, res.taxes_id)}
|
||||||
if not name:
|
if not name:
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
import dta
|
||||||
import dta_wizard
|
import dta_wizard
|
||||||
import invoice
|
import invoice
|
||||||
|
|
|
@ -30,9 +30,30 @@ from osv import osv,fields
|
||||||
|
|
||||||
class account_dta(osv.osv):
|
class account_dta(osv.osv):
|
||||||
_name = "account.dta"
|
_name = "account.dta"
|
||||||
_description = "DTA Management"
|
_description = "DTA History"
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.binary('DTA file', readonly=True),
|
'name': fields.binary('DTA file', readonly=True),
|
||||||
'note': fields.text('Error log'),
|
'dta_line_ids': fields.one2many('account.dta.line','dta_id','DTA lines', readonly=True),
|
||||||
|
'note': fields.text('Creation log', readonly=True),
|
||||||
|
'bank': fields.many2one('res.partner.bank','Bank', readonly=True),
|
||||||
|
'date': fields.date('Creation Date', readonly=True),
|
||||||
|
'user_id': fields.many2one('res.users','User', readonly=True),
|
||||||
}
|
}
|
||||||
account_dta()
|
account_dta()
|
||||||
|
|
||||||
|
class account_dta_line(osv.osv):
|
||||||
|
_name = "account.dta.line"
|
||||||
|
_description = "DTA line"
|
||||||
|
_columns = {
|
||||||
|
'name' : fields.many2one('account.invoice','Invoice'),
|
||||||
|
'partner_id' : fields.many2one('res.partner','Partner'),
|
||||||
|
'due_date' : fields.date('Due date'),
|
||||||
|
'cashdisc_date' : fields.date('Cash Discount date'),
|
||||||
|
'amount_to_pay' : fields.float('Amount to pay'),
|
||||||
|
'amount_invoice': fields.float('Invoiced Amount'),
|
||||||
|
'amount_cashdisc': fields.float('Cash Discount Amount'),
|
||||||
|
'dta_id': fields.many2one('account.dta','Associated DTA', required=True, ondelete='cascade'),
|
||||||
|
}
|
||||||
|
account_dta_line()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,23 @@
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record model="account.invoice" id="v11_invoice">
|
||||||
|
<field name="name">V11 invoice</field>
|
||||||
|
<field name="amount_total">54150</field>
|
||||||
|
<field name="number">1</field>
|
||||||
|
<field name="partner_id" ref="base.res_partner_agrolait"/>
|
||||||
|
<field name="address_invoice_id" ref="base.res_partner_address_8"/>
|
||||||
|
<field name="account_id" ref="account.a_recv"/>
|
||||||
|
<field name="currency_id" ref="base.EUR"/>
|
||||||
|
</record>
|
||||||
|
<record model="account.invoice.line" id="v11_invoice_line">
|
||||||
|
<field name="name">Dummy product</field>
|
||||||
|
<field name="price_unit">54150</field>
|
||||||
|
<field name="quantity">1</field>
|
||||||
|
<field name="account_id" ref="account.a_sale"/>
|
||||||
|
<field name="invoice_id" ref="v11_invoice"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record model="account.invoice" id="dta_invoice">
|
<record model="account.invoice" id="dta_invoice">
|
||||||
<field name="name">DTA invoice</field>
|
<field name="name">DTA invoice</field>
|
||||||
<field name="dta_state">2bpaid</field>
|
<field name="dta_state">2bpaid</field>
|
||||||
|
@ -41,23 +58,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<record model="account.invoice" id="v11_invoice">
|
|
||||||
<field name="name">V11 invoice</field>
|
|
||||||
<field name="amount_total">54150</field>
|
|
||||||
<field name="number">1</field>
|
|
||||||
<field name="partner_id" ref="base.res_partner_agrolait"/>
|
|
||||||
<field name="address_invoice_id" ref="base.res_partner_address_8"/>
|
|
||||||
<field name="account_id" ref="account.a_recv"/>
|
|
||||||
<field name="currency_id" ref="base.EUR"/>
|
|
||||||
</record>
|
|
||||||
<record model="account.invoice.line" id="v11_invoice_line">
|
|
||||||
<field name="name">Dummy product</field>
|
|
||||||
<field name="price_unit">54150</field>
|
|
||||||
<field name="quantity">1</field>
|
|
||||||
<field name="account_id" ref="account.a_sale"/>
|
|
||||||
<field name="invoice_id" ref="v11_invoice"/>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record model="account.journal" id="account.sales_journal">
|
<record model="account.journal" id="account.sales_journal">
|
||||||
<field name="default_debit_account_id" ref="account.a_recv"/>
|
<field name="default_debit_account_id" ref="account.a_recv"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record model="ir.ui.view" id="invoice_form">
|
<record model="ir.ui.view" id="invoice_form">
|
||||||
<field name="name">account.invoice.form</field>
|
<field name="name">account.invoice.form</field>
|
||||||
<field name="model">account.invoice</field>
|
<field name="model">account.invoice</field>
|
||||||
|
@ -36,5 +37,65 @@
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem name="Financial Management/Invoices/DTA invoices to pay" id="menu_account_dta_form" action="action_invoice_with_dta"/>
|
<menuitem name="Financial Management/Invoices/DTA invoices to pay" id="menu_account_dta_form" action="action_invoice_with_dta"/>
|
||||||
|
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="dta_line_tree">
|
||||||
|
<field name="name">account.dta.line.tree</field>
|
||||||
|
<field name="model">account.dta.line</field>
|
||||||
|
<field name="type">tree</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="DTA lines">
|
||||||
|
<field name="name" />
|
||||||
|
<field name="partner_id" />
|
||||||
|
<field name="due_date" />
|
||||||
|
<field name="amount_invoice" />
|
||||||
|
<field name="cashdisc_date" />
|
||||||
|
<field name="amount_cashdisc" />
|
||||||
|
<field name="amount_to_pay" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="account_dta_form">
|
||||||
|
<field name="name">account.dta.form</field>
|
||||||
|
<field name="model">account.dta</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="DTA">
|
||||||
|
<field name="name" />
|
||||||
|
<field name="bank" />
|
||||||
|
<field name="date" />
|
||||||
|
<field name="user_id" />
|
||||||
|
<field name="dta_line_ids" colspan="3"/>
|
||||||
|
<field name="note" colspan="3"/>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="account_dta_tree">
|
||||||
|
<field name="name">account.dta.tree</field>
|
||||||
|
<field name="model">account.dta</field>
|
||||||
|
<field name="type">tree</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="DTA">
|
||||||
|
<field name="bank" />
|
||||||
|
<field name="date" />
|
||||||
|
<field name="user_id" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.actions.act_window" id="action_account_dta">
|
||||||
|
<field name="name">account.dta</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">account.dta</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem name="Financial Management/Invoices/Generated DTA" id="menu_dta" action="action_account_dta"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</terp>
|
</terp>
|
||||||
|
|
|
@ -56,12 +56,20 @@ ask_fields = {
|
||||||
'selection':_bank_get,
|
'selection':_bank_get,
|
||||||
'required': True,
|
'required': True,
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# 'city' : {
|
check_form = """<?xml version="1.0"?>
|
||||||
# 'string':'Bank city',
|
<form string="DTA file creation">
|
||||||
# 'type':'char',
|
<separator colspan="4" string="DTA Details :" />
|
||||||
# },
|
<field name="dta_line_ids" nolabel="1" widget="one2many_list" colspan="4"/>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
check_fields = {
|
||||||
|
'dta_line_ids' : {
|
||||||
|
'string':'DTA lines',
|
||||||
|
'type':'one2many',
|
||||||
|
'relation':'account.dta.line',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,13 +89,11 @@ res_fields = {
|
||||||
'required':True,
|
'required':True,
|
||||||
'readonly':True,
|
'readonly':True,
|
||||||
},
|
},
|
||||||
|
|
||||||
'note' : {'string':'Log','type':'text'}
|
'note' : {'string':'Log','type':'text'}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_fields(self,cr,uid,data,context):
|
def _get_bank(self,cr,uid,data,context):
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
user = pool.get('res.users').browse(cr,uid,[uid])[0]
|
user = pool.get('res.users').browse(cr,uid,[uid])[0]
|
||||||
company= user.company_id
|
company= user.company_id
|
||||||
|
@ -95,8 +101,50 @@ def _get_fields(self,cr,uid,data,context):
|
||||||
if company.partner_id.bank_ids:
|
if company.partner_id.bank_ids:
|
||||||
bank = company.partner_id.bank_ids[0]
|
bank = company.partner_id.bank_ids[0]
|
||||||
return {'bank':bank.bank_name,'bank_iban':bank.iban or ''} # 'city':'',
|
return {'bank':bank.bank_name,'bank_iban':bank.iban or ''} # 'city':'',
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def _cleaning(self,cr,uid,data,context):
|
||||||
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
pool.get('account.dta').unlink(cr, uid, [ line[1] for line in data['form']['dta_line_ids'] ])
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_dta_lines(self,cr,uid,data,context):
|
||||||
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
dta_line_obj = pool.get('account.dta.line')
|
||||||
|
lines=[]
|
||||||
|
|
||||||
|
id_dta= pool.get('account.dta').create(cr,uid,{
|
||||||
|
'bank':data['form']['bank'],
|
||||||
|
'date':time.strftime('%Y-%m-%d'),
|
||||||
|
'user_id':uid,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
for i in pool.get('account.invoice').browse(cr,uid,data['ids']):
|
||||||
|
if i.dta_state != '2bpaid' or i.state in ['draft','cancel','paid']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
discount = i.payment_term and i.payment_term.cash_discount_ids and i.payment_term.cash_discount_ids[0] or False
|
||||||
|
if discount and time.strftime('%Y-%m-%d') <= discount.date :
|
||||||
|
amount_to_pay = i.amount_total*(1-discount.discount)
|
||||||
|
else :
|
||||||
|
amount_to_pay = i.amount_total
|
||||||
|
|
||||||
|
lines.append(dta_line_obj.create(cr,uid,{
|
||||||
|
'name':i.id,
|
||||||
|
'partner_id':i.partner_id.id,
|
||||||
|
'due_date':i.date_due,
|
||||||
|
'cashdisc_date': discount and discount.date,
|
||||||
|
'amount_to_pay': amount_to_pay,
|
||||||
|
'amount_invoice':i.amount_total,
|
||||||
|
'amount_cashdisc': discount and i.amount_total*(1-discount.discount),
|
||||||
|
'dta_id': id_dta,
|
||||||
|
}))
|
||||||
|
|
||||||
|
return {'dta_line_ids': lines}
|
||||||
|
|
||||||
def c_ljust(s, size):
|
def c_ljust(s, size):
|
||||||
"""
|
"""
|
||||||
check before calling ljust
|
check before calling ljust
|
||||||
|
@ -148,8 +196,8 @@ def _create_dta(self,cr,uid,data,context):
|
||||||
# cree des gt836
|
# cree des gt836
|
||||||
|
|
||||||
creation_date= time.strftime('%y%m%d')
|
creation_date= time.strftime('%y%m%d')
|
||||||
log=''
|
err_log=''
|
||||||
skip=''
|
std_log=''
|
||||||
dta=''
|
dta=''
|
||||||
valeur=''
|
valeur=''
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
@ -157,27 +205,40 @@ def _create_dta(self,cr,uid,data,context):
|
||||||
bank_name= bank.name or ''
|
bank_name= bank.name or ''
|
||||||
bank_iban = bank.iban or ''
|
bank_iban = bank.iban or ''
|
||||||
if not bank_name and bank_iban :
|
if not bank_name and bank_iban :
|
||||||
log= log +'\nBank account not well defined.'
|
err_log= err_log +'\nBank account not well defined.'
|
||||||
user = pool.get('res.users').browse(cr,uid,[uid])[0]
|
user = pool.get('res.users').browse(cr,uid,[uid])[0]
|
||||||
company= user.company_id
|
company= user.company_id
|
||||||
co_addr= company.partner_id.address[0]
|
co_addr= company.partner_id.address[0]
|
||||||
|
|
||||||
company_dta = company.dta_number or ''
|
company_dta = company.dta_number or ''
|
||||||
if not company.dta_number :
|
if not company.dta_number :
|
||||||
log= log +'\nNo dta number for the company.'
|
err_log= err_log +'\nNo dta number for the company.'
|
||||||
|
|
||||||
|
|
||||||
company_iban = company.partner_id and company.partner_id.bank_ids and company.partner_id.bank_ids[0]\
|
company_iban = company.partner_id and company.partner_id.bank_ids and company.partner_id.bank_ids[0]\
|
||||||
and company.partner_id.bank_ids[0].iban or ''
|
and company.partner_id.bank_ids[0].iban or ''
|
||||||
if not company_iban :
|
if not company_iban :
|
||||||
log= log +'\nNo iban number for the company.'
|
err_log= err_log +'\nNo iban number for the company.'
|
||||||
inv_obj = pool.get('account.invoice')
|
inv_obj = pool.get('account.invoice')
|
||||||
|
dta_line_obj = pool.get('account.dta.line')
|
||||||
seq= 1
|
seq= 1
|
||||||
amount_tot= 0
|
amount_tot= 0
|
||||||
for i in inv_obj.browse(cr,uid,data['ids']):
|
|
||||||
if i.dta_state != '2bpaid' or i.state in ['draft','cancel','paid']:
|
|
||||||
skip= skip +'\n Invoice '+ (i.number or '??')+ ' ignored.'
|
for dtal in dta_line_obj.browse(cr,uid,[ line[1] for line in data['form']['dta_line_ids'] ]):
|
||||||
continue
|
|
||||||
|
i = dtal.name #dta_line.name = invoice's id
|
||||||
|
|
||||||
|
std_log = std_log + '''
|
||||||
|
--
|
||||||
|
Invoice : %s
|
||||||
|
Partner : %s
|
||||||
|
Invoice amount : %d
|
||||||
|
Amount Paid : %d
|
||||||
|
''' % (i.name, i.partner_id.name,i.amount_total, dtal.amount_to_pay )
|
||||||
|
|
||||||
|
if dtal.cashdisc_date:
|
||||||
|
std_log = std_log + " Cash Discount : %d if paid before %s" % (dtal.amount_cashdisc, dtal.cashdisc_date)
|
||||||
|
|
||||||
number = i.number or ''
|
number = i.number or ''
|
||||||
currency = i.currency_id.code or ''
|
currency = i.currency_id.code or ''
|
||||||
|
@ -198,52 +259,51 @@ def _create_dta(self,cr,uid,data,context):
|
||||||
partner_city= ''
|
partner_city= ''
|
||||||
partner_zip= ''
|
partner_zip= ''
|
||||||
partner_country= ''
|
partner_country= ''
|
||||||
log= log +'\nNo address for the invoice partner.'
|
err_log= err_log +'\nNo address for the invoice partner.'
|
||||||
|
|
||||||
if not partner_bank_account:
|
if not partner_bank_account:
|
||||||
log= log +'\nNo bank account for the invoice partner. (invoice '+ (i.number or '??')+')'
|
err_log= err_log +'\nNo bank account for the invoice partner. (invoice '+ (i.number or '??')+')'
|
||||||
|
|
||||||
|
|
||||||
#header
|
#header
|
||||||
try:
|
try:
|
||||||
hdr= header('000000','',creation_date,company_iban,'idfi',seq,'836','0') # TODO id_file
|
hdr= header('000000','',creation_date,company_iban,'idfi',seq,'836','0') # TODO id_file
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
# segment 01:
|
# segment 01:
|
||||||
try:
|
try:
|
||||||
dta = dta + segment_01(hdr,company_dta ,
|
dta = dta + segment_01(hdr,company_dta ,
|
||||||
number,company_iban,valeur,currency,str(i.amount_total))
|
number,company_iban,valeur,currency,str(dtal.amount_to_pay))
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
# adresse donneur d'ordre
|
# adresse donneur d'ordre
|
||||||
try:
|
try:
|
||||||
dta = dta + segment_02(company.name,co_addr.street,co_addr.zip,co_addr.city,country,cours='')
|
dta = dta + segment_02(company.name,co_addr.street,co_addr.zip,co_addr.city,country,cours='')
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
# donnees de la banque
|
# donnees de la banque
|
||||||
try:
|
try:
|
||||||
dta = dta + segment_03(bank_name,'',bank_iban)
|
dta = dta + segment_03(bank_name,'',bank_iban)
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
# adresse du beneficiaire
|
# adresse du beneficiaire
|
||||||
try:
|
try:
|
||||||
dta = dta + segment_04(partner_name,partner_street,partner_zip,partner_city,partner_country,cours='')
|
dta = dta + segment_04(partner_name,partner_street,partner_zip,partner_city,partner_country,cours='')
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
# communication & reglement des frais
|
# communication & reglement des frais
|
||||||
try:
|
try:
|
||||||
dta = dta + segment_05(motif='I',ref1='',ref2=i.reference or '',ref3='',format='0') #FIXME : motif
|
dta = dta + segment_05(motif='I',ref1='',ref2=i.reference or '',ref3='',format='0') #FIXME : motif
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
|
|
||||||
|
amount_tot += dtal.amount_to_pay
|
||||||
amount_tot += i.amount_total
|
|
||||||
inv_obj.write(cr,uid,[i.id],{'dta_state':'paid'})
|
inv_obj.write(cr,uid,[i.id],{'dta_state':'paid'})
|
||||||
seq += 1
|
seq += 1
|
||||||
|
|
||||||
|
@ -254,24 +314,43 @@ def _create_dta(self,cr,uid,data,context):
|
||||||
dta = dta + total(header('000000','',creation_date,company_iban,str(uid),seq,'890','0')\
|
dta = dta + total(header('000000','',creation_date,company_iban,str(uid),seq,'890','0')\
|
||||||
, str(amount_tot))
|
, str(amount_tot))
|
||||||
except Exception,e :
|
except Exception,e :
|
||||||
log= log +'\n'+ str(e)
|
err_log= err_log +'\n'+ str(e)
|
||||||
#raise
|
#raise
|
||||||
|
|
||||||
log = log and log +'\nCORRUPTED FILE !'or 'DONE'
|
|
||||||
return {'note':log+skip, 'dta': b64encode(dta)}
|
err_log = err_log and 'CORRUPTED FILE !\n'+err_log or 'OK'
|
||||||
|
|
||||||
|
err_log = err_log + '\nParsed DTA lines :\n' + std_log
|
||||||
|
pool.get('account.dta').write(cr,uid,[dtal.dta_id.id],{'note':err_log,'name':b64encode(dta)})
|
||||||
|
|
||||||
|
return {'note':err_log, 'dta': b64encode(dta)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class wizard_dta_create(wizard.interface):
|
class wizard_dta_create(wizard.interface):
|
||||||
states = {
|
states = {
|
||||||
'init' : {
|
'init' : {
|
||||||
'actions' : [_get_fields],
|
'actions' : [_get_bank],
|
||||||
'result' : {'type' : 'form',
|
'result' : {'type' : 'form',
|
||||||
'arch' : ask_form,
|
'arch' : ask_form,
|
||||||
'fields' : ask_fields,
|
'fields' : ask_fields,
|
||||||
'state' : [('end', 'Cancel'),('creation', 'Yes') ]}
|
'state' : [('end', 'Cancel'),('check', 'Yes') ]}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'check':{
|
||||||
|
'actions' : [_get_dta_lines],
|
||||||
|
'result' : {'type' : 'form',
|
||||||
|
'arch' : check_form,
|
||||||
|
'fields' : check_fields,
|
||||||
|
'state' : [('clean', 'Cancel'),('creation', 'Yes') ]}
|
||||||
|
},
|
||||||
|
|
||||||
|
'clean':{
|
||||||
|
'actions' : [_cleaning],
|
||||||
|
'result' : {'type' : 'state',
|
||||||
|
'state' : 'end',}
|
||||||
|
},
|
||||||
|
|
||||||
'creation' : {
|
'creation' : {
|
||||||
'actions' : [_create_dta],
|
'actions' : [_create_dta],
|
||||||
'result' : {'type' : 'form',
|
'result' : {'type' : 'form',
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
# TODO : accepter les ligne meme si le payement est trop bas
|
||||||
|
# definir un try-catch ligne 221 et re-raiser si l'on le souhaite
|
||||||
|
|
||||||
|
|
||||||
import pooler
|
import pooler
|
||||||
import time
|
import time
|
||||||
import wizard
|
import wizard
|
||||||
|
@ -92,7 +98,8 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
total={}
|
total={}
|
||||||
total_compute= 0
|
total_compute= 0
|
||||||
rec_list=[]
|
rec_list=[]
|
||||||
log=''
|
err_log=''
|
||||||
|
std_log=''
|
||||||
nb_err=0
|
nb_err=0
|
||||||
|
|
||||||
# v11 parsing :
|
# v11 parsing :
|
||||||
|
@ -132,14 +139,14 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
'line_number': str(lnb),
|
'line_number': str(lnb),
|
||||||
}
|
}
|
||||||
|
|
||||||
total_compute+= int(record['montant'])
|
total_compute+= float(record['montant'])
|
||||||
rec_list.append( record )
|
rec_list.append( record )
|
||||||
|
|
||||||
lnb+=1
|
lnb+=1
|
||||||
line=""
|
line=""
|
||||||
|
|
||||||
# check the amounts :
|
# check the amounts :
|
||||||
if not total_compute == int(total['tot_montant']):
|
if not total_compute == float(total['tot_montant']):
|
||||||
return {'note': 'Incorrect total amount V11 file, import aborted.' }
|
return {'note': 'Incorrect total amount V11 file, import aborted.' }
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,15 +170,15 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
try:
|
try:
|
||||||
invoice_id= invoice_obj.search(cr,uid,[ ('number','=',int(rec['invoice_ref'])) ])[0]
|
invoice_id= invoice_obj.search(cr,uid,[ ('number','=',int(rec['invoice_ref'])) ])[0]
|
||||||
except:
|
except:
|
||||||
log = log + '\n * No invoice with invoice number '+ rec['invoice_ref'].lstrip('0') + '.\n line : '+rec['line']
|
err_log = err_log + '\n * No invoice with invoice number '+ rec['invoice_ref'].lstrip('0') + '.\n line : '+rec['line_number']
|
||||||
nb_err+=1
|
nb_err+=1
|
||||||
continue
|
continue
|
||||||
invoice = invoice_obj.browse(cr, uid, invoice_id)
|
i = invoice_obj.browse(cr, uid, invoice_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
acc1 = invoice.partner_id.property_account_receivable[0]
|
acc1 = i.partner_id.property_account_receivable[0]
|
||||||
except:
|
except:
|
||||||
log = log + '\n * invoice with number '+ rec['invoice_ref'].lstrip('0') +' has no partner !'+ '\n line : '+rec['line']
|
err_log = err_log + '\n * invoice with number '+ rec['invoice_ref'].lstrip('0') +' has no partner !'+ '\n line : '+rec['line_number']
|
||||||
nb_err+=1
|
nb_err+=1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -187,7 +194,7 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
'credit': rec['montant'],
|
'credit': rec['montant'],
|
||||||
'account_id': acc1,
|
'account_id': acc1,
|
||||||
'move_id': move_id,
|
'move_id': move_id,
|
||||||
'partner_id': invoice.partner_id.id,
|
'partner_id': i.partner_id.id,
|
||||||
'date': time.strftime('%Y-%m-%d'),
|
'date': time.strftime('%Y-%m-%d'),
|
||||||
'period_id': period_id,
|
'period_id': period_id,
|
||||||
'journal_id': data['form']['journal_id']
|
'journal_id': data['form']['journal_id']
|
||||||
|
@ -199,52 +206,67 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
'credit': 0,
|
'credit': 0,
|
||||||
'account_id': acc2,
|
'account_id': acc2,
|
||||||
'move_id': move_id,
|
'move_id': move_id,
|
||||||
'partner_id': invoice.partner_id.id,
|
'partner_id': i.partner_id.id,
|
||||||
'date': time.strftime('%Y-%m-%d'),
|
'date': time.strftime('%Y-%m-%d'),
|
||||||
'period_id': period_id,
|
'period_id': period_id,
|
||||||
'journal_id': data['form']['journal_id']
|
'journal_id': data['form']['journal_id']
|
||||||
|
|
||||||
})
|
})
|
||||||
account_move_lines = invoice.move_line_id_payment_get(cr,uid,[invoice.id])
|
account_move_lines = i.move_line_id_payment_get(cr,uid,[i.id])
|
||||||
|
|
||||||
if not account_move_lines:
|
if not account_move_lines:
|
||||||
raise Exception("No moves associated to invoice number "+ rec['invoice_ref'].lstrip('0'))
|
raise Exception("No moves associated to invoice number "+ rec['invoice_ref'].lstrip('0'))
|
||||||
account_move_lines.append(line_id )
|
account_move_lines.append(line_id )
|
||||||
pool.get('account.move.line').reconcile(cr,uid,account_move_lines,
|
|
||||||
writeoff_acc_id=0,
|
pool.get('account.move.line').reconcile(cr,uid,account_move_lines,
|
||||||
writeoff_journal_id=0,
|
writeoff_acc_id=0,
|
||||||
writeoff_period_id= 0,
|
writeoff_journal_id=0,
|
||||||
)
|
writeoff_period_id= 0,
|
||||||
|
)
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
|
||||||
|
std_log = std_log + """
|
||||||
|
--
|
||||||
|
Invoice : %s
|
||||||
|
Date Due : %s
|
||||||
|
Amount received : %.2f
|
||||||
|
"""%(i.name, i.date_due or 'undefined', float(rec['montant']))
|
||||||
|
if i.payment_term and i.payment_term.cash_discount_ids and i.payment_term.cash_discount_ids[0]:
|
||||||
|
if discount and rec['date_remise'] <= discount.date :
|
||||||
|
amount_to_pay = i.amount_total*(1-discount.discount)
|
||||||
|
else :
|
||||||
|
amount_to_pay = i.amount_total
|
||||||
|
|
||||||
|
std_log = std_log + " Amount expected : %d"% amount_to_pay
|
||||||
|
|
||||||
except osv.except_osv, e:
|
except osv.except_osv, e:
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
nb_err+=1
|
nb_err+=1
|
||||||
if e.value.startswith('You have to provide an account for the write off entry !'):
|
if e.value.startswith('You have to provide an account for the write off entry !'):
|
||||||
log= log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
err_log= err_log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
||||||
' : Amount mismatch for invoice '+ rec['invoice_ref'].lstrip('0')+\
|
' : Amount mismatch for invoice '+ rec['invoice_ref'].lstrip('0')+\
|
||||||
'( expected amount: '+str(invoice.amount_total)+' got :'+rec['montant'].lstrip('0')+\
|
'( expected amount: '+str(i.amount_total)+' got :'+rec['montant'].lstrip('0')+\
|
||||||
').'
|
').'
|
||||||
else:
|
else:
|
||||||
log= log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
err_log= err_log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
||||||
' : '+str(e.value)
|
' : '+str(e.value)
|
||||||
#raise # REMOVEME
|
#raise # REMOVEME
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
nb_err+=1
|
nb_err+=1
|
||||||
log= log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
err_log= err_log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+\
|
||||||
' : '+str(e)
|
' : '+str(e)
|
||||||
#raise # REMOVEME
|
#raise # REMOVEME
|
||||||
except :
|
except :
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
nb_err+=1
|
nb_err+=1
|
||||||
log= log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+' : Reconciliation Error.'
|
err_log= err_log +'\n * Line '+rec['line_number'] +', invoice '+rec['invoice_ref'].lstrip('0')+' : Reconciliation Error.'
|
||||||
#raise
|
#raise
|
||||||
|
|
||||||
log= log + '\n\n --' +'\nNumber of parsed lines : '+ str(len(rec_list)) +'\nNumber of error : '+ str(nb_err)
|
err_log= err_log + '\n\n --' +'\nNumber of parsed lines : '+ str(len(rec_list)) +'\nNumber of error : '+ str(nb_err)
|
||||||
|
|
||||||
return {'note':log,'journal_id': data['form']['journal_id'], 'v11': data['form']['v11']}
|
return {'note':err_log+ std_log,'journal_id': data['form']['journal_id'], 'v11': data['form']['v11']}
|
||||||
|
|
||||||
|
|
||||||
# def _init(self, cr, uid, data, context):
|
# def _init(self, cr, uid, data, context):
|
||||||
|
|
Loading…
Reference in New Issue