replace tabs with 4 spaces

bzr revid: christophe@tinyerp.com-20080722151128-f5zy75tsn8pgtndd
This commit is contained in:
Christophe Simonis 2008-07-22 17:11:28 +02:00
parent 2dd9723b8b
commit d2ff95f665
255 changed files with 22328 additions and 22328 deletions

View File

@ -26,51 +26,51 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Accounting and financial management",
"version" : "1.0",
"depends" : ["product", "base"],
"author" : "Tiny",
"description": """Financial and accounting module that covers:
General accounting
Cost / Analytic accounting
Third party accounting
Taxes management
Budgets
""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [
"name" : "Accounting and financial management",
"version" : "1.0",
"depends" : ["product", "base"],
"author" : "Tiny",
"description": """Financial and accounting module that covers:
General accounting
Cost / Analytic accounting
Third party accounting
Taxes management
Budgets
""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [
],
"demo_xml" : [
"account_demo.xml",
"project/project_demo.xml",
"project/analytic_account_demo.xml",
"account_unit_test.xml",
],
"update_xml" : [
"account_wizard.xml",
"account_view.xml",
"account_end_fy.xml",
"account_invoice_view.xml",
"account_report.xml",
"partner_view.xml",
"data/account_invoice.xml",
"data/account_data1.xml",
"data/account_minimal.xml",
"data/account_data2.xml",
"account_invoice_workflow.xml",
"project/project_view.xml",
"project/project_report.xml",
"product_data.xml",
"product_view.xml",
"account_security.xml",
"project/project_security.xml",
"account_assert_test.xml",
],
"translations" : {
"fr": "i18n/french_fr.csv"
},
"active": False,
"installable": True
],
"demo_xml" : [
"account_demo.xml",
"project/project_demo.xml",
"project/analytic_account_demo.xml",
"account_unit_test.xml",
],
"update_xml" : [
"account_wizard.xml",
"account_view.xml",
"account_end_fy.xml",
"account_invoice_view.xml",
"account_report.xml",
"partner_view.xml",
"data/account_invoice.xml",
"data/account_data1.xml",
"data/account_minimal.xml",
"data/account_data2.xml",
"account_invoice_workflow.xml",
"project/project_view.xml",
"project/project_report.xml",
"product_data.xml",
"product_view.xml",
"account_security.xml",
"project/project_security.xml",
"account_assert_test.xml",
],
"translations" : {
"fr": "i18n/french_fr.csv"
},
"active": False,
"installable": True
}

File diff suppressed because it is too large Load Diff

View File

@ -35,97 +35,97 @@ from osv import osv
from tools.translate import _
class account_analytic_line(osv.osv):
_name = 'account.analytic.line'
_description = 'Analytic lines'
_columns = {
'name' : fields.char('Description', size=256, required=True),
'date' : fields.date('Date', required=True),
'amount' : fields.float('Amount', required=True),
'unit_amount' : fields.float('Quantity'),
'product_uom_id' : fields.many2one('product.uom', 'UoM'),
'product_id' : fields.many2one('product.product', 'Product'),
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
'general_account_id' : fields.many2one('account.account', 'General account', required=True, ondelete='cascade'),
'move_id' : fields.many2one('account.move.line', 'General entry', ondelete='cascade', select=True),
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic journal', required=True, ondelete='cascade', select=True),
'code' : fields.char('Code', size=8),
'user_id' : fields.many2one('res.users', 'User',),
'ref': fields.char('Ref.', size=32),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
}
_order = 'date'
def _check_company(self, cr, uid, ids):
lines = self.browse(cr, uid, ids)
for l in lines:
if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id:
return False
return True
_constraints = [
(_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id'])
]
_name = 'account.analytic.line'
_description = 'Analytic lines'
_columns = {
'name' : fields.char('Description', size=256, required=True),
'date' : fields.date('Date', required=True),
'amount' : fields.float('Amount', required=True),
'unit_amount' : fields.float('Quantity'),
'product_uom_id' : fields.many2one('product.uom', 'UoM'),
'product_id' : fields.many2one('product.product', 'Product'),
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
'general_account_id' : fields.many2one('account.account', 'General account', required=True, ondelete='cascade'),
'move_id' : fields.many2one('account.move.line', 'General entry', ondelete='cascade', select=True),
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic journal', required=True, ondelete='cascade', select=True),
'code' : fields.char('Code', size=8),
'user_id' : fields.many2one('res.users', 'User',),
'ref': fields.char('Ref.', size=32),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
}
_order = 'date'
def _check_company(self, cr, uid, ids):
lines = self.browse(cr, uid, ids)
for l in lines:
if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id:
return False
return True
_constraints = [
(_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id'])
]
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,
unit=False, context=None):
uom_obj = self.pool.get('product.uom')
product_obj = self.pool.get('product.product')
if unit_amount and prod_id:
prod = product_obj.browse(cr, uid, prod_id)
a = prod.product_tmpl_id.property_account_expense.id
if not a:
a = prod.categ_id.property_account_expense_categ.id
if not a:
raise osv.except_osv(_('Error !'),
_('There is no expense account define ' \
'for this product: "%s" (id:%d)') % \
(prod.name, prod.id,))
amount = unit_amount * uom_obj._compute_price(cr, uid,
prod.uom_id.id, prod.standard_price, unit)
return {'value': {
'amount': - round(amount, 2),
'general_account_id': a,
}}
return {}
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,
unit=False, context=None):
uom_obj = self.pool.get('product.uom')
product_obj = self.pool.get('product.product')
if unit_amount and prod_id:
prod = product_obj.browse(cr, uid, prod_id)
a = prod.product_tmpl_id.property_account_expense.id
if not a:
a = prod.categ_id.property_account_expense_categ.id
if not a:
raise osv.except_osv(_('Error !'),
_('There is no expense account define ' \
'for this product: "%s" (id:%d)') % \
(prod.name, prod.id,))
amount = unit_amount * uom_obj._compute_price(cr, uid,
prod.uom_id.id, prod.standard_price, unit)
return {'value': {
'amount': - round(amount, 2),
'general_account_id': a,
}}
return {}
account_analytic_line()
class timesheet_invoice(osv.osv):
_name = "report.hr.timesheet.invoice.journal"
_description = "Analytic account costs and revenues"
_auto = False
_columns = {
'name': fields.date('Month', readonly=True),
'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True, select=True),
'journal_id': fields.many2one('account.analytic.journal', 'Journal', readonly=True),
'quantity': fields.float('Quantities', readonly=True),
'cost': fields.float('Credit', readonly=True),
'revenue': fields.float('Debit', readonly=True)
}
_order = 'name desc, account_id'
def init(self, cr):
cr.execute("""
create or replace view report_hr_timesheet_invoice_journal as (
select
min(l.id) as id,
date_trunc('month', l.date)::date as name,
sum(
CASE WHEN l.amount>0 THEN 0 ELSE l.amount
END
) as cost,
sum(
CASE WHEN l.amount>0 THEN l.amount ELSE 0
END
) as revenue,
sum(l.unit_amount* COALESCE(u.factor, 1)) as quantity,
journal_id,
account_id
from account_analytic_line l
LEFT OUTER join product_uom u on (u.id=l.product_uom_id)
group by
date_trunc('month', l.date),
journal_id,
account_id
)""")
_name = "report.hr.timesheet.invoice.journal"
_description = "Analytic account costs and revenues"
_auto = False
_columns = {
'name': fields.date('Month', readonly=True),
'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True, select=True),
'journal_id': fields.many2one('account.analytic.journal', 'Journal', readonly=True),
'quantity': fields.float('Quantities', readonly=True),
'cost': fields.float('Credit', readonly=True),
'revenue': fields.float('Debit', readonly=True)
}
_order = 'name desc, account_id'
def init(self, cr):
cr.execute("""
create or replace view report_hr_timesheet_invoice_journal as (
select
min(l.id) as id,
date_trunc('month', l.date)::date as name,
sum(
CASE WHEN l.amount>0 THEN 0 ELSE l.amount
END
) as cost,
sum(
CASE WHEN l.amount>0 THEN l.amount ELSE 0
END
) as revenue,
sum(l.unit_amount* COALESCE(u.factor, 1)) as quantity,
journal_id,
account_id
from account_analytic_line l
LEFT OUTER join product_uom u on (u.id=l.product_uom_id)
group by
date_trunc('month', l.date),
journal_id,
account_id
)""")
timesheet_invoice()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -32,94 +32,94 @@ from osv import fields, osv
import ir
class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
_description = 'Partner'
def _credit_get(self, cr, uid, ids, name, arg, context):
res={}
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('receivable', id))
res[id]=cr.fetchone()[0] or 0.0
return res
_name = 'res.partner'
_inherit = 'res.partner'
_description = 'Partner'
def _credit_get(self, cr, uid, ids, name, arg, context):
res={}
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('receivable', id))
res[id]=cr.fetchone()[0] or 0.0
return res
def _debit_get(self, cr, uid, ids, name, arg, context):
res={}
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('payable', id))
res[id]=cr.fetchone()[0] or 0.0
return res
def _debit_get(self, cr, uid, ids, name, arg, context):
res={}
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('payable', id))
res[id]=cr.fetchone()[0] or 0.0
return res
def _credit_search(self, cr, uid, obj, name, args):
if not len(args):
return []
where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('receivable',) )
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
def _credit_search(self, cr, uid, obj, name, args):
if not len(args):
return []
where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('receivable',) )
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
def _debit_search(self, cr, uid, obj, name, args):
if not len(args):
return []
query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('payable',) )
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
def _debit_search(self, cr, uid, obj, name, args):
if not len(args):
return []
query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('payable',) )
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
_columns = {
'credit': fields.function(_credit_get, fnct_search=_credit_search, method=True, string='Total Receivable'),
'debit': fields.function(_debit_get, fnct_search=_debit_search, method=True, string='Total Payable'),
'debit_limit': fields.float('Payable Limit'),
'property_account_payable': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Account Payable",
method=True,
view_load=True,
group_name="Accounting Properties",
domain="[('type', '=', 'payable')]",
help="This account will be used, instead of the default one, as the payable account for the current partner",
required=True),
'property_account_receivable': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Account Receivable",
method=True,
view_load=True,
group_name="Accounting Properties",
domain="[('type', '=', 'receivable')]",
help="This account will be used, instead of the default one, as the receivable account for the current partner",
required=True),
'property_account_tax': fields.property(
'account.tax',
type='many2one',
relation='account.tax',
string="Default Tax",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This tax will be used, instead of the default one."),
'property_payment_term': fields.property(
'account.payment.term',
type='many2one',
relation='account.payment.term',
string ='Payment Term',
method=True,
view_load=True,
group_name="Accounting Properties",
help="This payment term will be used, instead of the default one, for the current partner"),
'ref_companies': fields.one2many('res.company', 'partner_id',
'Companies that refers to partner'),
}
_columns = {
'credit': fields.function(_credit_get, fnct_search=_credit_search, method=True, string='Total Receivable'),
'debit': fields.function(_debit_get, fnct_search=_debit_search, method=True, string='Total Payable'),
'debit_limit': fields.float('Payable Limit'),
'property_account_payable': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Account Payable",
method=True,
view_load=True,
group_name="Accounting Properties",
domain="[('type', '=', 'payable')]",
help="This account will be used, instead of the default one, as the payable account for the current partner",
required=True),
'property_account_receivable': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Account Receivable",
method=True,
view_load=True,
group_name="Accounting Properties",
domain="[('type', '=', 'receivable')]",
help="This account will be used, instead of the default one, as the receivable account for the current partner",
required=True),
'property_account_tax': fields.property(
'account.tax',
type='many2one',
relation='account.tax',
string="Default Tax",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This tax will be used, instead of the default one."),
'property_payment_term': fields.property(
'account.payment.term',
type='many2one',
relation='account.payment.term',
string ='Payment Term',
method=True,
view_load=True,
group_name="Accounting Properties",
help="This payment term will be used, instead of the default one, for the current partner"),
'ref_companies': fields.one2many('res.company', 'partner_id',
'Companies that refers to partner'),
}
res_partner()

View File

@ -33,58 +33,58 @@ import netsvc
from osv import fields, osv
class product_category(osv.osv):
_inherit = "product.category"
_columns = {
'property_account_income_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product category"),
'property_account_expense_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product category"),
}
_inherit = "product.category"
_columns = {
'property_account_income_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product category"),
'property_account_expense_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product category"),
}
product_category()
#----------------------------------------------------------
# Products
#----------------------------------------------------------
class product_template(osv.osv):
_inherit = "product.template"
_columns = {
'taxes_id': fields.many2many('account.tax', 'product_taxes_rel',
'prod_id', 'tax_id', 'Customer Taxes',
domain=[('parent_id','=',False)]),
'supplier_taxes_id': fields.many2many('account.tax',
'product_supplier_taxes_rel', 'prod_id', 'tax_id',
'Supplier Taxes', domain=[('parent_id', '=', False)]),
'property_account_income': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product"),
'property_account_expense': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product"),
}
_inherit = "product.template"
_columns = {
'taxes_id': fields.many2many('account.tax', 'product_taxes_rel',
'prod_id', 'tax_id', 'Customer Taxes',
domain=[('parent_id','=',False)]),
'supplier_taxes_id': fields.many2many('account.tax',
'product_supplier_taxes_rel', 'prod_id', 'tax_id',
'Supplier Taxes', domain=[('parent_id', '=', False)]),
'property_account_income': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product"),
'property_account_expense': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product"),
}
product_template()

View File

@ -38,202 +38,202 @@ from osv import osv
#
class account_analytic_account(osv.osv):
_name = 'account.analytic.account'
_description = 'Analytic Accounts'
_name = 'account.analytic.account'
_description = 'Analytic Accounts'
def _credit_calc(self, cr, uid, ids, name, arg, context={}):
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount<0 and a.id IN (%s) GROUP BY a.id" % acc_set)
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
def _credit_calc(self, cr, uid, ids, name, arg, context={}):
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount<0 and a.id IN (%s) GROUP BY a.id" % acc_set)
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
def _debit_calc(self, cr, uid, ids, name, arg, context={}):
def _debit_calc(self, cr, uid, ids, name, arg, context={}):
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount>0 and a.id IN (%s) GROUP BY a.id" % acc_set)
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount>0 and a.id IN (%s) GROUP BY a.id" % acc_set)
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
def _balance_calc(self, cr, uid, ids, name, arg, context={}):
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE a.id IN (%s) GROUP BY a.id" % acc_set)
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
def _balance_calc(self, cr, uid, ids, name, arg, context={}):
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE a.id IN (%s) GROUP BY a.id" % acc_set)
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set)
cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set)
currency= dict(cr.fetchall())
currency= dict(cr.fetchall())
res_currency= self.pool.get('res.currency')
for id in ids:
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child <> id:
res.setdefault(id, 0.0)
if currency[child]<>currency[id] :
res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)
else:
res[id] += res.get(child, 0.0)
res_currency= self.pool.get('res.currency')
for id in ids:
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child <> id:
res.setdefault(id, 0.0)
if currency[child]<>currency[id] :
res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)
else:
res[id] += res.get(child, 0.0)
cur_obj = res_currency.browse(cr,uid,currency.values(),context)
cur_obj = dict([(o.id, o) for o in cur_obj])
for id in ids:
res[id] = res_currency.round(cr,uid,cur_obj[currency[id]],res.get(id,0.0))
cur_obj = res_currency.browse(cr,uid,currency.values(),context)
cur_obj = dict([(o.id, o) for o in cur_obj])
for id in ids:
res[id] = res_currency.round(cr,uid,cur_obj[currency[id]],res.get(id,0.0))
return dict([(i, res[i]) for i in ids ])
return dict([(i, res[i]) for i in ids ])
def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
#XXX must convert into one uom
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
FROM account_analytic_account a \
LEFT JOIN account_analytic_line l ON (a.id = l.account_id) \
WHERE a.id IN ('+acc_set+') GROUP BY a.id')
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
#XXX must convert into one uom
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
FROM account_analytic_account a \
LEFT JOIN account_analytic_line l ON (a.id = l.account_id) \
WHERE a.id IN ('+acc_set+') GROUP BY a.id')
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
for id in ids:
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child <> id:
res.setdefault(id, 0.0)
res[id] += res.get(child, 0.0)
return dict([(i, res[i]) for i in ids])
for id in ids:
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child <> id:
res.setdefault(id, 0.0)
res[id] += res.get(child, 0.0)
return dict([(i, res[i]) for i in ids])
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name','parent_id'], context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
res.append((record['id'], name))
return res
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name','parent_id'], context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
res.append((record['id'], name))
return res
def _complete_name_calc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
res = self.name_get(cr, uid, ids)
return dict(res)
def _complete_name_calc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
res = self.name_get(cr, uid, ids)
return dict(res)
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
result = {}
for rec in self.browse(cr, uid, ids, context):
result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False
return result
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
result = {}
for rec in self.browse(cr, uid, ids, context):
result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False
return result
_columns = {
'name' : fields.char('Account name', size=64, required=True),
'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Account Name'),
'code' : fields.char('Account code', size=24),
'active' : fields.boolean('Active'),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Account type'),
'description' : fields.text('Description'),
'parent_id': fields.many2one('account.analytic.account', 'Parent analytic account', select=2),
'child_ids': fields.one2many('account.analytic.account', 'parent_id', 'Childs Accounts'),
'line_ids': fields.one2many('account.analytic.line', 'account_id', 'Analytic entries'),
'balance' : fields.function(_balance_calc, method=True, type='float', string='Balance'),
'debit' : fields.function(_debit_calc, method=True, type='float', string='Debit'),
'credit' : fields.function(_credit_calc, method=True, type='float', string='Credit'),
'quantity': fields.function(_quantity_calc, method=True, type='float', string='Quantity'),
'quantity_max': fields.float('Maximal quantity'),
'partner_id' : fields.many2one('res.partner', 'Associated partner'),
'contact_id' : fields.many2one('res.partner.address', 'Contact'),
'user_id' : fields.many2one('res.users', 'Account Manager'),
'date_start': fields.date('Date Start'),
'date': fields.date('Date End'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
'state': fields.selection([('draft','Draft'), ('open','Open'), ('pending','Pending'), ('close','Close'),], 'State', required=True),
}
_columns = {
'name' : fields.char('Account name', size=64, required=True),
'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Account Name'),
'code' : fields.char('Account code', size=24),
'active' : fields.boolean('Active'),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Account type'),
'description' : fields.text('Description'),
'parent_id': fields.many2one('account.analytic.account', 'Parent analytic account', select=2),
'child_ids': fields.one2many('account.analytic.account', 'parent_id', 'Childs Accounts'),
'line_ids': fields.one2many('account.analytic.line', 'account_id', 'Analytic entries'),
'balance' : fields.function(_balance_calc, method=True, type='float', string='Balance'),
'debit' : fields.function(_debit_calc, method=True, type='float', string='Debit'),
'credit' : fields.function(_credit_calc, method=True, type='float', string='Credit'),
'quantity': fields.function(_quantity_calc, method=True, type='float', string='Quantity'),
'quantity_max': fields.float('Maximal quantity'),
'partner_id' : fields.many2one('res.partner', 'Associated partner'),
'contact_id' : fields.many2one('res.partner.address', 'Contact'),
'user_id' : fields.many2one('res.users', 'Account Manager'),
'date_start': fields.date('Date Start'),
'date': fields.date('Date End'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
'state': fields.selection([('draft','Draft'), ('open','Open'), ('pending','Pending'), ('close','Close'),], 'State', required=True),
}
def _default_company(self, cr, uid, context={}):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
return user.company_id.id
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
_defaults = {
'active' : lambda *a : True,
'type' : lambda *a : 'normal',
'company_id': _default_company,
'state' : lambda *a : 'draft',
'user_id' : lambda self,cr,uid,ctx : uid
}
def _default_company(self, cr, uid, context={}):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
return user.company_id.id
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
_defaults = {
'active' : lambda *a : True,
'type' : lambda *a : 'normal',
'company_id': _default_company,
'state' : lambda *a : 'draft',
'user_id' : lambda self,cr,uid,ctx : uid
}
def check_recursion(self, cr, uid, ids, parent=None):
return super(account_analytic_account, self).check_recursion(cr, uid, ids, parent=parent)
def check_recursion(self, cr, uid, ids, parent=None):
return super(account_analytic_account, self).check_recursion(cr, uid, ids, parent=parent)
_order = 'parent_id desc,code'
_constraints = [
(check_recursion, 'Error! You can not create recursive account.', ['parent_id'])
]
_order = 'parent_id desc,code'
_constraints = [
(check_recursion, 'Error! You can not create recursive account.', ['parent_id'])
]
def create(self, cr, uid, vals, context=None):
parent_id = vals.get('parent_id', 0)
if ('code' not in vals or not vals['code']) and not parent_id:
vals['code'] = self.pool.get('ir.sequence').get(cr, uid, 'account.analytic.account')
return super(account_analytic_account, self).create(cr, uid, vals, context=context)
def create(self, cr, uid, vals, context=None):
parent_id = vals.get('parent_id', 0)
if ('code' not in vals or not vals['code']) and not parent_id:
vals['code'] = self.pool.get('ir.sequence').get(cr, uid, 'account.analytic.account')
return super(account_analytic_account, self).create(cr, uid, vals, context=context)
def copy(self, cr, uid, id, default=None, context={}):
if not default:
default = {}
default['code'] = False
return super(account_analytic_account, self).copy(cr, uid, id, default, context=context)
def copy(self, cr, uid, id, default=None, context={}):
if not default:
default = {}
default['code'] = False
return super(account_analytic_account, self).copy(cr, uid, id, default, context=context)
def on_change_parent(self, cr, uid, id, parent_id):
if not parent_id:
return {}
parent = self.read(cr, uid, [parent_id], ['partner_id','code'])[0]
childs = self.search(cr, uid, [('parent_id', '=', parent_id), ('active', 'in', [True, False])])
numchild = len(childs)
if parent['partner_id']:
partner = parent['partner_id'][0]
else:
partner = False
res = {'value' : {'code' : '%s - %03d' % (parent['code'] or '', numchild + 1),}}
if partner:
res['value']['partner_id'] = partner
return res
def on_change_parent(self, cr, uid, id, parent_id):
if not parent_id:
return {}
parent = self.read(cr, uid, [parent_id], ['partner_id','code'])[0]
childs = self.search(cr, uid, [('parent_id', '=', parent_id), ('active', 'in', [True, False])])
numchild = len(childs)
if parent['partner_id']:
partner = parent['partner_id'][0]
else:
partner = False
res = {'value' : {'code' : '%s - %03d' % (parent['code'] or '', numchild + 1),}}
if partner:
res['value']['partner_id'] = partner
return res
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
if not args:
args=[]
if not context:
context={}
account = self.search(cr, uid, [('code', '=', name)]+args, limit=limit, context=context)
if not account:
account = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name)]+args, limit=limit, context=context)
newacc = account
while newacc:
newacc = self.search(cr, uid, [('parent_id', 'in', newacc)]+args, limit=limit, context=context)
account+=newacc
return self.name_get(cr, uid, account, context=context)
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
if not args:
args=[]
if not context:
context={}
account = self.search(cr, uid, [('code', '=', name)]+args, limit=limit, context=context)
if not account:
account = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name)]+args, limit=limit, context=context)
newacc = account
while newacc:
newacc = self.search(cr, uid, [('parent_id', 'in', newacc)]+args, limit=limit, context=context)
account+=newacc
return self.name_get(cr, uid, account, context=context)
account_analytic_account()
class account_analytic_journal(osv.osv):
_name = 'account.analytic.journal'
_columns = {
'name' : fields.char('Journal name', size=64, required=True),
'code' : fields.char('Journal code', size=8),
'active' : fields.boolean('Active'),
'type': fields.selection([('sale','Sale'), ('purchase','Purchase'), ('cash','Cash'), ('general','General'), ('situation','Situation')], 'Type', size=32, required=True, help="Gives the type of the analytic journal. When a document (eg: an invoice) needs to create analytic entries, Tiny ERP will look for a matching journal of the same type."),
'line_ids' : fields.one2many('account.analytic.line', 'journal_id', 'Lines'),
}
_defaults = {
'active': lambda *a: True,
'type': lambda *a: 'general',
}
_name = 'account.analytic.journal'
_columns = {
'name' : fields.char('Journal name', size=64, required=True),
'code' : fields.char('Journal code', size=8),
'active' : fields.boolean('Active'),
'type': fields.selection([('sale','Sale'), ('purchase','Purchase'), ('cash','Cash'), ('general','General'), ('situation','Situation')], 'Type', size=32, required=True, help="Gives the type of the analytic journal. When a document (eg: an invoice) needs to create analytic entries, Tiny ERP will look for a matching journal of the same type."),
'line_ids' : fields.one2many('account.analytic.line', 'journal_id', 'Lines'),
}
_defaults = {
'active': lambda *a: True,
'type': lambda *a: 'general',
}
account_analytic_journal()
@ -242,42 +242,42 @@ account_analytic_journal()
# ---------------------------------------------------------
#class account_analytic_budget_post(osv.osv):
# _name = 'account.analytic.budget.post'
# _description = 'Budget item'
# _columns = {
# 'code': fields.char('Code', size=64, required=True),
# 'name': fields.char('Name', size=256, required=True),
# 'sens': fields.selection( [('charge','Charge'), ('produit','Product')], 'Direction', required=True),
# 'dotation_ids': fields.one2many('account.analytic.budget.post.dotation', 'post_id', 'Expenses'),
# 'account_ids': fields.many2many('account.analytic.account', 'account_analytic_budget_rel', 'budget_id', 'account_id', 'Accounts'),
# }
# _defaults = {
# 'sens': lambda *a: 'produit',
# }
# _name = 'account.analytic.budget.post'
# _description = 'Budget item'
# _columns = {
# 'code': fields.char('Code', size=64, required=True),
# 'name': fields.char('Name', size=256, required=True),
# 'sens': fields.selection( [('charge','Charge'), ('produit','Product')], 'Direction', required=True),
# 'dotation_ids': fields.one2many('account.analytic.budget.post.dotation', 'post_id', 'Expenses'),
# 'account_ids': fields.many2many('account.analytic.account', 'account_analytic_budget_rel', 'budget_id', 'account_id', 'Accounts'),
# }
# _defaults = {
# 'sens': lambda *a: 'produit',
# }
#
# def spread(self, cr, uid, ids, fiscalyear_id=False, quantity=0.0, amount=0.0):
# def spread(self, cr, uid, ids, fiscalyear_id=False, quantity=0.0, amount=0.0):
#
# dobj = self.pool.get('account.analytic.budget.post.dotation')
# for o in self.browse(cr, uid, ids):
# # delete dotations for this post
# dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)]))
# dobj = self.pool.get('account.analytic.budget.post.dotation')
# for o in self.browse(cr, uid, ids):
# # delete dotations for this post
# dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)]))
#
# # create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations
# fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0]
# num = len(fy.period_ids)
# for p in fy.period_ids:
# dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'quantity': quantity/num, 'amount': amount/num})
# return True
# # create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations
# fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0]
# num = len(fy.period_ids)
# for p in fy.period_ids:
# dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'quantity': quantity/num, 'amount': amount/num})
# return True
#account_analytic_budget_post()
#
#class account_analytic_budget_post_dotation(osv.osv):
# _name = 'account.analytic.budget.post.dotation'
# _description = "Budget item endowment"
# _columns = {
# 'name': fields.char('Name', size=64),
# 'post_id': fields.many2one('account.analytic.budget.post', 'Item', select=True),
# 'period_id': fields.many2one('account.period', 'Period'),
# 'quantity': fields.float('Quantity', digits=(16,2)),
# 'amount': fields.float('Amount', digits=(16,2)),
# }
# _name = 'account.analytic.budget.post.dotation'
# _description = "Budget item endowment"
# _columns = {
# 'name': fields.char('Name', size=64),
# 'post_id': fields.many2one('account.analytic.budget.post', 'Item', select=True),
# 'period_id': fields.many2one('account.period', 'Period'),
# 'quantity': fields.float('Quantity', digits=(16,2)),
# 'amount': fields.float('Amount', digits=(16,2)),
# }
#account_analytic_budget_post_dotation()

View File

@ -35,20 +35,20 @@ from report import report_sxw
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse):
def lines(self, journal_id, *args):
self.cr.execute('select id from account_analytic_line where journal_id=%d order by date,id', (journal_id,))
ids = map(lambda x: x[0], self.cr.fetchall())
res = self.pool.get('account.analytic.line').browse(self.cr, self.uid, ids)
return res
def _sum_lines(self, journal_id):
self.cr.execute('select sum(amount) from account_analytic_line where journal_id=%d', (journal_id,))
return self.cr.fetchone()[0] or 0.0
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext = {
'time': time,
'lines': self.lines,
'sum_lines': self._sum_lines,
}
def lines(self, journal_id, *args):
self.cr.execute('select id from account_analytic_line where journal_id=%d order by date,id', (journal_id,))
ids = map(lambda x: x[0], self.cr.fetchall())
res = self.pool.get('account.analytic.line').browse(self.cr, self.uid, ids)
return res
def _sum_lines(self, journal_id):
self.cr.execute('select sum(amount) from account_analytic_line where journal_id=%d', (journal_id,))
return self.cr.fetchone()[0] or 0.0
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext = {
'time': time,
'lines': self.lines,
'sum_lines': self._sum_lines,
}
report_sxw.report_sxw('report.account.analytic.journal.print', 'account.analytic.journal', 'addons/account/project/report/analytic_journal.rml',parser=journal_print)

View File

@ -32,137 +32,137 @@ import time
from report import report_sxw
class account_analytic_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'move_sum_debit': self._move_sum_debit,
'move_sum_credit': self._move_sum_credit,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
'sum_quantity': self._sum_quantity,
'move_sum_balance': self._move_sum_balance,
'move_sum_quantity': self._move_sum_quantity,
})
def __init__(self, cr, uid, name, context):
super(account_analytic_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'move_sum_debit': self._move_sum_debit,
'move_sum_credit': self._move_sum_credit,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
'sum_quantity': self._sum_quantity,
'move_sum_balance': self._move_sum_balance,
'move_sum_quantity': self._move_sum_quantity,
})
def _lines_g(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) \
AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\
AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
ORDER BY aal.code", (date1, date2))
res = self.cr.dictfetchall()
def _lines_g(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) \
AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\
AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
ORDER BY aal.code", (date1, date2))
res = self.cr.dictfetchall()
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['balance'] == 0
r['debit'] = 0.0
r['credit'] = 0.0
return res
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['balance'] == 0
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _move_sum_debit(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s AND amount>0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _move_sum_debit(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s AND amount>0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _move_sum_credit(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s AND amount<0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _move_sum_credit(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s AND amount<0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _move_sum_balance(self, account_id, date1, date2):
debit = self._move_sum_debit(account_id, date1, date2)
credit = self._move_sum_credit(account_id, date1, date2)
return (debit-credit)
def _move_sum_balance(self, account_id, date1, date2):
debit = self._move_sum_debit(account_id, date1, date2)
credit = self._move_sum_credit(account_id, date1, date2)
return (debit-credit)
def _move_sum_quantity(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _move_sum_quantity(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id in ("+ ','.join(map(str, ids)) +") \
AND date>=%s AND date<=%s",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s AND amount>0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s AND amount>0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
ids = map(lambda x: x.id, accounts)
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s AND amount<0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
ids = map(lambda x: x.id, accounts)
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s AND amount<0",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2) or 0.0
credit = self._sum_credit(accounts, date1, date2) or 0.0
return (debit-credit)
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2) or 0.0
credit = self._sum_credit(accounts, date1, date2) or 0.0
return (debit-credit)
def _sum_quantity(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_quantity(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
account_analytic_obj = self.pool.get('account.analytic.account')
ids2 = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', ids)])
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids2))+") \
AND date>=%s AND date<=%s",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.analytic.account.balance',
'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
parser=account_analytic_balance, header=False)
'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
parser=account_analytic_balance, header=False)

View File

@ -32,75 +32,75 @@ import time
from report import report_sxw
class account_analytic_analytic_check(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_analytic_check, self).__init__(cr, uid, name, context)
self.sum_gen_deb = 0.0
self.sum_gen_cred = 0.0
self.sum_ana_deb = 0.0
self.sum_ana_cred = 0.0
self.localcontext.update( {
'time': time,
'lines_p': self._lines_p,
'general_debit': self._gen_deb,
'general_credit': self._gen_cred,
'analytic_debit': self._ana_deb,
'analytic_credit': self._ana_cred,
'delta_debit': self._delta_deb,
'delta_credit': self._delta_cred,
})
def __init__(self, cr, uid, name, context):
super(account_analytic_analytic_check, self).__init__(cr, uid, name, context)
self.sum_gen_deb = 0.0
self.sum_gen_cred = 0.0
self.sum_ana_deb = 0.0
self.sum_ana_cred = 0.0
self.localcontext.update( {
'time': time,
'lines_p': self._lines_p,
'general_debit': self._gen_deb,
'general_credit': self._gen_cred,
'analytic_debit': self._ana_deb,
'analytic_credit': self._ana_cred,
'delta_debit': self._delta_deb,
'delta_credit': self._delta_cred,
})
def _lines_p(self, date1, date2):
res = []
acc_obj = self.pool.get('account.account')
for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code', 'sign']):
self.cr.execute("SELECT sum(debit), sum(credit) \
FROM account_move_line \
WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %d", (date1, date2, a['id']))
(gd, gc) = self.cr.fetchone()
gd = gd or 0.0
gc = gc or 0.0
def _lines_p(self, date1, date2):
res = []
acc_obj = self.pool.get('account.account')
for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code', 'sign']):
self.cr.execute("SELECT sum(debit), sum(credit) \
FROM account_move_line \
WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %d", (date1, date2, a['id']))
(gd, gc) = self.cr.fetchone()
gd = gd or 0.0
gc = gc or 0.0
self.cr.execute("SELECT abs(sum(amount)) AS balance \
FROM account_analytic_line \
WHERE date>=%s AND date<=%s AND amount*%d>0 AND general_account_id = %d", (date1, date2, a['sign'], a['id']))
(ad,) = self.cr.fetchone()
ad = ad or 0.0
self.cr.execute("SELECT abs(sum(amount)) AS balance \
FROM account_analytic_line \
WHERE date>=%s AND date<=%s AND amount*%d<0 AND general_account_id = %d", (date1, date2, a['sign'], a['id']))
(ac,) = self.cr.fetchone()
ac = ac or 0.0
self.cr.execute("SELECT abs(sum(amount)) AS balance \
FROM account_analytic_line \
WHERE date>=%s AND date<=%s AND amount*%d>0 AND general_account_id = %d", (date1, date2, a['sign'], a['id']))
(ad,) = self.cr.fetchone()
ad = ad or 0.0
self.cr.execute("SELECT abs(sum(amount)) AS balance \
FROM account_analytic_line \
WHERE date>=%s AND date<=%s AND amount*%d<0 AND general_account_id = %d", (date1, date2, a['sign'], a['id']))
(ac,) = self.cr.fetchone()
ac = ac or 0.0
res.append({'code': a['code'], 'name': a['name'],
'gen_debit': gd,
'gen_credit': gc,
'ana_debit': ad,
'ana_credit': ac,
'delta_debit': gd - ad,
'delta_credit': gc - ac,})
self.sum_gen_deb += gd
self.sum_gen_cred += gc
self.sum_ana_deb += ad
self.sum_ana_cred += ac
return res
res.append({'code': a['code'], 'name': a['name'],
'gen_debit': gd,
'gen_credit': gc,
'ana_debit': ad,
'ana_credit': ac,
'delta_debit': gd - ad,
'delta_credit': gc - ac,})
self.sum_gen_deb += gd
self.sum_gen_cred += gc
self.sum_ana_deb += ad
self.sum_ana_cred += ac
return res
def _gen_deb(self, date1, date2):
return self.sum_gen_deb
def _gen_deb(self, date1, date2):
return self.sum_gen_deb
def _gen_cred(self, date1, date2):
return self.sum_gen_cred
def _gen_cred(self, date1, date2):
return self.sum_gen_cred
def _ana_deb(self, date1, date2):
return self.sum_ana_deb
def _ana_deb(self, date1, date2):
return self.sum_ana_deb
def _ana_cred(self, date1, date2):
return self.sum_ana_cred
def _ana_cred(self, date1, date2):
return self.sum_ana_cred
def _delta_deb(self, date1, date2):
return (self._gen_deb(date1,date2)-self._ana_deb(date1,date2))
def _delta_deb(self, date1, date2):
return (self._gen_deb(date1,date2)-self._ana_deb(date1,date2))
def _delta_cred(self, date1, date2):
return (self._gen_cred(date1,date2)-self._ana_cred(date1,date2))
def _delta_cred(self, date1, date2):
return (self._gen_cred(date1,date2)-self._ana_cred(date1,date2))
report_sxw.report_sxw('report.account.analytic.account.analytic.check', 'account.analytic.account', 'addons/account/project/report/analytic_check.rml',parser=account_analytic_analytic_check, header=False)

View File

@ -34,35 +34,35 @@ from report import report_sxw
# Use period and Journal for selection or resources
#
class account_analytic_journal(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_journal, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self._lines,
'lines_a': self._lines_a,
'sum_general': self._sum_general,
'sum_analytic': self._sum_analytic,
})
def __init__(self, cr, uid, name, context):
super(account_analytic_journal, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self._lines,
'lines_a': self._lines_a,
'sum_general': self._sum_general,
'sum_analytic': self._sum_analytic,
})
def _lines(self, journal_id, date1, date2):
self.cr.execute('SELECT DISTINCT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%d) AND (move_id is not null)', (date1, date2, journal_id,))
ids = map(lambda x: x[0], self.cr.fetchall())
return self.pool.get('account.move.line').browse(self.cr, self.uid, ids)
def _lines(self, journal_id, date1, date2):
self.cr.execute('SELECT DISTINCT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%d) AND (move_id is not null)', (date1, date2, journal_id,))
ids = map(lambda x: x[0], self.cr.fetchall())
return self.pool.get('account.move.line').browse(self.cr, self.uid, ids)
def _lines_a(self, move_id, journal_id, date1, date2):
ids = self.pool.get('account.analytic.line').search(self.cr, self.uid, [('move_id','=',move_id), ('journal_id','=',journal_id), ('date','>=',date1), ('date','<=',date2)])
if not ids:
return []
return self.pool.get('account.analytic.line').browse(self.cr, self.uid, ids)
def _lines_a(self, move_id, journal_id, date1, date2):
ids = self.pool.get('account.analytic.line').search(self.cr, self.uid, [('move_id','=',move_id), ('journal_id','=',journal_id), ('date','>=',date1), ('date','<=',date2)])
if not ids:
return []
return self.pool.get('account.analytic.line').browse(self.cr, self.uid, ids)
def _sum_general(self, journal_id, date1, date2):
self.cr.execute('SELECT SUM(debit-credit) FROM account_move_line WHERE id IN (SELECT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%d) AND (move_id is not null))', (date1, date2, journal_id,))
return self.cr.fetchall()[0][0] or 0
def _sum_general(self, journal_id, date1, date2):
self.cr.execute('SELECT SUM(debit-credit) FROM account_move_line WHERE id IN (SELECT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%d) AND (move_id is not null))', (date1, date2, journal_id,))
return self.cr.fetchall()[0][0] or 0
def _sum_analytic(self, journal_id, date1, date2):
self.cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE date>=%s AND date<=%s AND journal_id=%d", (date1, date2, journal_id))
res = self.cr.dictfetchone()
return res['sum'] or 0
def _sum_analytic(self, journal_id, date1, date2):
self.cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE date>=%s AND date<=%s AND journal_id=%d", (date1, date2, journal_id))
res = self.cr.dictfetchone()
return res['sum'] or 0
report_sxw.report_sxw('report.account.analytic.journal', 'account.analytic.journal', 'addons/account/project/report/analytic_journal.rml',parser=account_analytic_journal)

View File

@ -32,90 +32,90 @@ import time
from report import report_sxw
class account_analytic_cost_ledger(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'account_sum_debit': self._account_sum_debit,
'account_sum_credit': self._account_sum_credit,
'account_sum_balance': self._account_sum_balance,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
})
def __init__(self, cr, uid, name, context):
super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'account_sum_debit': self._account_sum_debit,
'account_sum_credit': self._account_sum_credit,
'account_sum_balance': self._account_sum_balance,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
})
def _lines_g(self, account_id, date1, date2):
self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (account_id, date1, date2))
res = self.cr.dictfetchall()
def _lines_g(self, account_id, date1, date2):
self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (account_id, date1, date2))
res = self.cr.dictfetchall()
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _lines_a(self, general_account_id, account_id, date1, date2):
self.cr.execute("SELECT aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj FROM account_analytic_line AS aal, account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) \
ORDER BY aal.date, aaj.code, aal.code", (general_account_id, account_id, date1, date2))
res = self.cr.dictfetchall()
def _lines_a(self, general_account_id, account_id, date1, date2):
self.cr.execute("SELECT aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj FROM account_analytic_line AS aal, account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) \
ORDER BY aal.date, aaj.code, aal.code", (general_account_id, account_id, date1, date2))
res = self.cr.dictfetchall()
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _account_sum_debit(self, account_id, date1, date2):
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id=%d AND date>=%s AND date<=%s AND amount>0", (account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _account_sum_debit(self, account_id, date1, date2):
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id=%d AND date>=%s AND date<=%s AND amount>0", (account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _account_sum_credit(self, account_id, date1, date2):
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id=%d AND date>=%s AND date<=%s AND amount<0", (account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _account_sum_credit(self, account_id, date1, date2):
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id=%d AND date>=%s AND date<=%s AND amount<0", (account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _account_sum_balance(self, account_id, date1, date2):
debit = self._account_sum_debit(account_id, date1, date2)
credit = self._account_sum_credit(account_id, date1, date2)
return (debit-credit)
def _account_sum_balance(self, account_id, date1, date2):
debit = self._account_sum_debit(account_id, date1, date2)
credit = self._account_sum_credit(account_id, date1, date2)
return (debit-credit)
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2) or 0.0
credit = self._sum_credit(accounts, date1, date2) or 0.0
return (debit-credit)
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2) or 0.0
credit = self._sum_credit(accounts, date1, date2) or 0.0
return (debit-credit)
report_sxw.report_sxw('report.account.analytic.account.cost_ledger', 'account.analytic.account', 'addons/account/project/report/cost_ledger.rml',parser=account_analytic_cost_ledger, header=False)

View File

@ -32,89 +32,89 @@ import time
from report import report_sxw
class account_inverted_analytic_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_inverted_analytic_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
'sum_quantity': self._sum_quantity,
})
def __init__(self, cr, uid, name, context):
super(account_inverted_analytic_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
'sum_quantity': self._sum_quantity,
})
def _lines_g(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) AND (aal.account_id IN ("+','.join(map(str, ids))+")) AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2))
res = self.cr.dictfetchall()
def _lines_g(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) AND (aal.account_id IN ("+','.join(map(str, ids))+")) AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2))
res = self.cr.dictfetchall()
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _lines_a(self, accounts, general_account_id, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \
FROM account_analytic_line AS aal, account_analytic_account AS aaa \
WHERE aal.account_id=aaa.id AND aal.account_id IN ("+','.join(map(str, ids))+") AND aal.general_account_id=%d AND aal.date>=%s AND aal.date<=%s \
GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2))
res = self.cr.dictfetchall()
def _lines_a(self, accounts, general_account_id, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \
FROM account_analytic_line AS aal, account_analytic_account AS aaa \
WHERE aal.account_id=aaa.id AND aal.account_id IN ("+','.join(map(str, ids))+") AND aal.general_account_id=%d AND aal.date>=%s AND aal.date<=%s \
GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2))
res = self.cr.dictfetchall()
aaa_obj = self.pool.get('account.analytic.account')
res2 = aaa_obj.read(self.cr, self.uid, ids, ['complete_name'])
complete_name = {}
for r in res2:
complete_name[r['id']] = r['complete_name']
for r in res:
r['complete_name'] = complete_name[r['account_id']]
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
aaa_obj = self.pool.get('account.analytic.account')
res2 = aaa_obj.read(self.cr, self.uid, ids, ['complete_name'])
complete_name = {}
for r in res2:
complete_name[r['id']] = r['complete_name']
for r in res:
r['complete_name'] = complete_name[r['account_id']]
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2)
credit = self._sum_credit(accounts, date1, date2)
return (debit-credit)
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_debit(accounts, date1, date2)
credit = self._sum_credit(accounts, date1, date2)
return (debit-credit)
def _sum_quantity(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_quantity(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.analytic.account.inverted.balance', 'account.analytic.account', 'addons/account/project/report/inverted_analytic_balance.rml',parser=account_inverted_analytic_balance, header=False)

View File

@ -32,109 +32,109 @@ import time
from report import report_sxw
class account_analytic_quantity_cost_ledger(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_quantity_cost_ledger, self).__init__(cr, uid,
name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'sum_quantity': self._sum_quantity,
'account_sum_quantity': self._account_sum_quantity,
})
def __init__(self, cr, uid, name, context):
super(account_analytic_quantity_cost_ledger, self).__init__(cr, uid,
name, context)
self.localcontext.update( {
'time': time,
'lines_g': self._lines_g,
'lines_a': self._lines_a,
'sum_quantity': self._sum_quantity,
'account_sum_quantity': self._account_sum_quantity,
})
def _lines_g(self, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) \
AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
AND aa.active \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
(account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) \
AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
AND aa.active \
AND (aal.journal_id IN (" +
','.join(map(str, journal_ids)) + ")) \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
(account_id, date1, date2))
res = self.cr.dictfetchall()
return res
def _lines_g(self, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) \
AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
AND aa.active \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
(account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
aa.code AS code, aa.name AS name, aa.id AS id \
FROM account_account AS aa, account_analytic_line AS aal \
WHERE (aal.account_id=%d) AND (aal.date>=%s) \
AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
AND aa.active \
AND (aal.journal_id IN (" +
','.join(map(str, journal_ids)) + ")) \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
(account_id, date1, date2))
res = self.cr.dictfetchall()
return res
def _lines_a(self, general_account_id, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
aal.unit_amount AS quantity, aal.date AS date, \
aaj.code AS cj \
FROM account_analytic_line AS aal, \
account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) \
AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) \
ORDER BY aal.date, aaj.code, aal.code",
(general_account_id, account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
aal.unit_amount AS quantity, aal.date AS date, \
aaj.code AS cj \
FROM account_analytic_line AS aal, \
account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) \
AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) AND (aaj.id IN (" +
','.join(map(str, journal_ids)) + ")) \
ORDER BY aal.date, aaj.code, aal.code",
(general_account_id, account_id, date1, date2))
res = self.cr.dictfetchall()
return res
def _lines_a(self, general_account_id, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
aal.unit_amount AS quantity, aal.date AS date, \
aaj.code AS cj \
FROM account_analytic_line AS aal, \
account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) \
AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) \
ORDER BY aal.date, aaj.code, aal.code",
(general_account_id, account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
aal.unit_amount AS quantity, aal.date AS date, \
aaj.code AS cj \
FROM account_analytic_line AS aal, \
account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%d) AND (aal.account_id=%d) \
AND (aal.date>=%s) AND (aal.date<=%s) \
AND (aal.journal_id=aaj.id) AND (aaj.id IN (" +
','.join(map(str, journal_ids)) + ")) \
ORDER BY aal.date, aaj.code, aal.code",
(general_account_id, account_id, date1, date2))
res = self.cr.dictfetchall()
return res
def _account_sum_quantity(self, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id=%d AND date>=%s AND date<=%s",
(account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id = %d AND date >= %s AND date <= %s \
AND journal_id IN (" +
','.join(map(str, journal_ids)) + ")",
(account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _account_sum_quantity(self, account_id, date1, date2, journals):
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id=%d AND date>=%s AND date<=%s",
(account_id, date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id = %d AND date >= %s AND date <= %s \
AND journal_id IN (" +
','.join(map(str, journal_ids)) + ")",
(account_id, date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_quantity(self, accounts, date1, date2, journals):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN (" +
','.join(map(str, ids)) + ") AND date>=%s AND date<=%s",
(date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN (" +
','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \
AND journal_id IN (" +
','.join(map(str, journal_ids)) + ")",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
def _sum_quantity(self, accounts, date1, date2, journals):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
if not journals or not journals[0][2]:
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN (" +
','.join(map(str, ids)) + ") AND date>=%s AND date<=%s",
(date1, date2))
else:
journal_ids = journals[0][2]
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
WHERE account_id IN (" +
','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \
AND journal_id IN (" +
','.join(map(str, journal_ids)) + ")",
(date1, date2))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger',
'account.analytic.account',
'addons/account/project/report/quantity_cost_ledger.rml',
parser=account_analytic_quantity_cost_ledger, header=False)
'account.analytic.account',
'addons/account/project/report/quantity_cost_ledger.rml',
parser=account_analytic_quantity_cost_ledger, header=False)

View File

@ -32,26 +32,26 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.analytic.check', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.analytic.check', 'state':'end'}
}
}
wizard_report('account.analytic.account.analytic.check.report')

View File

@ -32,27 +32,27 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.balance', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.balance', 'state':'end'}
}
}
wizard_report('account.analytic.account.balance.report')

View File

@ -32,42 +32,42 @@ import wizard
_form = '''<?xml version="1.0"?>
<form string="Select period">
<separator string="Cost Legder for period" colspan="4"/>
<field name="date1"/>
<field name="date2"/>
<separator string="and Journals" colspan="4"/>
<field name="journal" colspan="4"/>
<separator string="Cost Legder for period" colspan="4"/>
<field name="date1"/>
<field name="date2"/>
<separator string="and Journals" colspan="4"/>
<field name="journal" colspan="4"/>
</form>'''
_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'journal': {'string':'Journals','type':'many2many', 'relation':'account.analytic.journal'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'journal': {'string':'Journals','type':'many2many', 'relation':'account.analytic.journal'},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': _form,
'fields': _fields,
'state': [
('end','Cancel'),
('report','Print')
]
}
},
'report': {
'actions': [],
'result': {
'type': 'print',
'report': 'account.analytic.account.quantity_cost_ledger',
'state': 'end'
}
},
}
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': _form,
'fields': _fields,
'state': [
('end','Cancel'),
('report','Print')
]
}
},
'report': {
'actions': [],
'result': {
'type': 'print',
'report': 'account.analytic.account.quantity_cost_ledger',
'state': 'end'
}
},
}
wizard_report('account.analytic.account.quantity_cost_ledger.report')

View File

@ -32,26 +32,26 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.cost_ledger', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.cost_ledger', 'state':'end'}
}
}
wizard_report('account.analytic.account.cost_ledger.report')

View File

@ -32,26 +32,26 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.inverted.balance', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.account.inverted.balance', 'state':'end'}
}
}
wizard_report('account.analytic.account.inverted.balance.report')

View File

@ -32,25 +32,25 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Analytic Journal Report">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.journal', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'), ('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.analytic.journal', 'state':'end'}
}
}
wizard_report('account.analytic.account.journal.report')

View File

@ -31,93 +31,93 @@ import time
from report import report_sxw
class account_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_balance, self).__init__(cr, uid, name, context)
self.sum_debit = 0.0
self.sum_credit = 0.0
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_fiscalyear':self.get_fiscalyear,
'get_periods':self.get_periods,
})
self.context = context
def __init__(self, cr, uid, name, context):
super(account_balance, self).__init__(cr, uid, name, context)
self.sum_debit = 0.0
self.sum_credit = 0.0
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_fiscalyear':self.get_fiscalyear,
'get_periods':self.get_periods,
})
self.context = context
def get_fiscalyear(self, form):
fisc_id = form['fiscalyear']
if not(fisc_id):
return ''
self.cr.execute("select name from account_fiscalyear where id = %d" %(int(fisc_id)))
res=self.cr.fetchone()
return res and res[0] or ''
def get_fiscalyear(self, form):
fisc_id = form['fiscalyear']
if not(fisc_id):
return ''
self.cr.execute("select name from account_fiscalyear where id = %d" %(int(fisc_id)))
res=self.cr.fetchone()
return res and res[0] or ''
def get_periods(self, form):
period_ids = ",".join([str(x) for x in form['periods'][0][2] if x])
self.cr.execute("select name from account_period where id in (%s)" % (period_ids))
res=self.cr.fetchall()
result=''
for r in res:
result+=r[0]+","
return str(result and result[:-1]) or ''
def get_periods(self, form):
period_ids = ",".join([str(x) for x in form['periods'][0][2] if x])
self.cr.execute("select name from account_period where id in (%s)" % (period_ids))
res=self.cr.fetchall()
result=''
for r in res:
result+=r[0]+","
return str(result and result[:-1]) or ''
def lines(self, form, ids={}, done=None, level=1):
if not ids:
ids = self.ids
if not ids:
return []
if not done:
done={}
result = []
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
ctx['target_move'] = form['target_move']
accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)
def cmp_code(x, y):
return cmp(x.code, y.code)
accounts.sort(cmp_code)
for account in accounts:
if account.id in done:
continue
done[account.id] = 1
res = {
'code': account.code,
'name': account.name,
'level': level,
'debit': account.debit,
'credit': account.credit,
'balance': account.balance,
'leef': not bool(account.child_id)
}
self.sum_debit += account.debit
self.sum_credit += account.credit
if not (res['credit'] or res['debit']) and not account.child_id:
continue
if account.child_id:
def _check_rec(account):
if not account.child_id:
return bool(account.credit or account.debit)
for c in account.child_id:
if _check_rec(c):
return True
return False
if not _check_rec(account):
continue
def lines(self, form, ids={}, done=None, level=1):
if not ids:
ids = self.ids
if not ids:
return []
if not done:
done={}
result = []
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
ctx['target_move'] = form['target_move']
accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)
def cmp_code(x, y):
return cmp(x.code, y.code)
accounts.sort(cmp_code)
for account in accounts:
if account.id in done:
continue
done[account.id] = 1
res = {
'code': account.code,
'name': account.name,
'level': level,
'debit': account.debit,
'credit': account.credit,
'balance': account.balance,
'leef': not bool(account.child_id)
}
self.sum_debit += account.debit
self.sum_credit += account.credit
if not (res['credit'] or res['debit']) and not account.child_id:
continue
if account.child_id:
def _check_rec(account):
if not account.child_id:
return bool(account.credit or account.debit)
for c in account.child_id:
if _check_rec(c):
return True
return False
if not _check_rec(account):
continue
result.append(res)
if account.child_id:
ids2 = [(x.code,x.id) for x in account.child_id]
ids2.sort()
result += self.lines(form, [x[1] for x in ids2], done, level+1)
return result
result.append(res)
if account.child_id:
ids2 = [(x.code,x.id) for x in account.child_id]
ids2.sort()
result += self.lines(form, [x[1] for x in ids2], done, level+1)
return result
def _sum_credit(self):
return self.sum_credit
def _sum_credit(self):
return self.sum_credit
def _sum_debit(self):
return self.sum_debit
def _sum_debit(self):
return self.sum_debit
report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance, header=2)

View File

@ -35,28 +35,28 @@ from report import report_sxw
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def lines(self, period_id, journal_id, *args):
self.cr.execute('update account_journal_period set state=%s where journal_id=%d and period_id=%d and state=%s', ('printed',journal_id,period_id,'draft'))
self.cr.commit()
self.cr.execute('select id from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\' order by date,id', (period_id, journal_id))
ids = map(lambda x: x[0], self.cr.fetchall())
return self.pool.get('account.move.line').browse(self.cr, self.uid, ids)
def lines(self, period_id, journal_id, *args):
self.cr.execute('update account_journal_period set state=%s where journal_id=%d and period_id=%d and state=%s', ('printed',journal_id,period_id,'draft'))
self.cr.commit()
self.cr.execute('select id from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\' order by date,id', (period_id, journal_id))
ids = map(lambda x: x[0], self.cr.fetchall())
return self.pool.get('account.move.line').browse(self.cr, self.uid, ids)
def _sum_debit(self, period_id, journal_id):
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, period_id, journal_id):
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, period_id, journal_id):
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, period_id, journal_id):
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.journal.period.print', 'account.journal.period', 'addons/account/report/account_journal.rml', parser=journal_print)

View File

@ -32,160 +32,160 @@ import pooler
from report import report_sxw
class aged_trial_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(aged_trial_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'get_lines': self._get_lines,
'get_total': self._get_total,
'get_before': self._get_before,
'get_for_period': self._get_for_period,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def __init__(self, cr, uid, name, context):
super(aged_trial_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'get_lines': self._get_lines,
'get_total': self._get_total,
'get_before': self._get_before,
'get_for_period': self._get_for_period,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def _add_header(self, node):
return True
def _add_header(self, node):
return True
def _get_lines(self, form):
self.form=form
res = []
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': form['fiscalyear']})
self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \
"res_partner.name AS name, res_partner.ref AS code " \
"FROM res_partner, account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (line.reconcile_id IS NULL) " \
"AND (line.partner_id=res_partner.id) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active " \
"ORDER BY res_partner.name", (form['company_id'],))
partners = self.cr.dictfetchall()
for partner in partners:
values = {}
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (account_account.type IN (" + form['computation'] +")) " \
"AND (date < %s) AND (partner_id=%d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(form['0']['start'], partner['id'], form['company_id']))
before = self.cr.fetchone()
values['before'] = before and before[0] or ""
for i in range(5):
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (account_account.type IN (" + form['computation'] + ")) " \
"AND (date >= %s) AND (date <= %s) " \
"AND (partner_id = %d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(form[str(i)]['start'], form[str(i)]['stop'],
partner['id'], form['company_id']))
during = self.cr.fetchone()
values[str(i)] = during and during[0] or ""
def _get_lines(self, form):
self.form=form
res = []
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': form['fiscalyear']})
self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \
"res_partner.name AS name, res_partner.ref AS code " \
"FROM res_partner, account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (line.reconcile_id IS NULL) " \
"AND (line.partner_id=res_partner.id) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active " \
"ORDER BY res_partner.name", (form['company_id'],))
partners = self.cr.dictfetchall()
for partner in partners:
values = {}
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (account_account.type IN (" + form['computation'] +")) " \
"AND (date < %s) AND (partner_id=%d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(form['0']['start'], partner['id'], form['company_id']))
before = self.cr.fetchone()
values['before'] = before and before[0] or ""
for i in range(5):
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id=account_account.id) " \
"AND (account_account.type IN (" + form['computation'] + ")) " \
"AND (date >= %s) AND (date <= %s) " \
"AND (partner_id = %d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(form[str(i)]['start'], form[str(i)]['stop'],
partner['id'], form['company_id']))
during = self.cr.fetchone()
values[str(i)] = during and during[0] or ""
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + form['computation'] + ")) " \
"AND (partner_id = %d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(partner['id'], form['company_id']))
total = self.cr.fetchone()
values['total'] = total and total[0] or 0.0
values['name'] = partner['name']
values['ref'] = partner['code']
t = 0.0
for i in range(5)+['before']:
t+= float(values.get(str(i), 0.0) or 0.0)
if values['total']:
res.append(values)
total = 0.0
totals = {}
for r in res:
total += float(r['total'] or 0.0)
for i in range(5)+['before']:
totals.setdefault(str(i), 0.0)
totals[str(i)] += float(r[str(i)] or 0.0)
if form['sorting_on']=='amount':
res.sort(lambda x,y:cmp(y['total'],x['total']))
return res
self.cr.execute("SELECT SUM(debit-credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + form['computation'] + ")) " \
"AND (partner_id = %d) " \
"AND (reconcile_id IS NULL) " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(partner['id'], form['company_id']))
total = self.cr.fetchone()
values['total'] = total and total[0] or 0.0
values['name'] = partner['name']
values['ref'] = partner['code']
t = 0.0
for i in range(5)+['before']:
t+= float(values.get(str(i), 0.0) or 0.0)
if values['total']:
res.append(values)
total = 0.0
totals = {}
for r in res:
total += float(r['total'] or 0.0)
for i in range(5)+['before']:
totals.setdefault(str(i), 0.0)
totals[str(i)] += float(r[str(i)] or 0.0)
if form['sorting_on']=='amount':
res.sort(lambda x,y:cmp(y['total'],x['total']))
return res
def _get_total(self, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) "\
"AND reconcile_id IS NULL " \
"AND partner_id is NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(company_id,))
total = self.cr.fetchone()
return total and total[0] or 0.0
def _get_total(self, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) "\
"AND reconcile_id IS NULL " \
"AND partner_id is NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(company_id,))
total = self.cr.fetchone()
return total and total[0] or 0.0
def _get_before(self, date, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) " \
"AND reconcile_id IS NULL " \
"AND (date < %s) " \
"AND partner_id IS NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(date, company_id))
before = self.cr.fetchone()
return before and before[0] or 0.0
def _get_before(self, date, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) " \
"AND reconcile_id IS NULL " \
"AND (date < %s) " \
"AND partner_id IS NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(date, company_id))
before = self.cr.fetchone()
return before and before[0] or 0.0
def _get_for_period(self, period, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) " \
"AND reconcile_id IS NULL " \
"AND (date >= %s) " \
"AND (date <= %s) " \
"AND partner_id IS NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(period['start'], period['stop'], company_id))
period = self.cr.fetchone()
return period and period[0] or 0.0
def _get_for_period(self, period, fiscalyear, company_id):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': fiscalyear})
self.cr.execute("SELECT SUM(debit - credit) " \
"FROM account_move_line AS line, account_account " \
"WHERE (line.account_id = account_account.id) " \
"AND (account_account.type IN (" + self.form['computation'] + ")) " \
"AND reconcile_id IS NULL " \
"AND (date >= %s) " \
"AND (date <= %s) " \
"AND partner_id IS NOT NULL " \
"AND " + line_query + " " \
"AND (account_account.company_id = %d) " \
"AND account_account.active",
(period['start'], period['stop'], company_id))
period = self.cr.fetchone()
return period and period[0] or 0.0
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw(
'report.account.aged.trial.balance',
'res.partner',
'addons/account/report/aged_trial_balance.rml',
parser=aged_trial_report, header=False)
'report.account.aged.trial.balance',
'res.partner',
'addons/account/report/aged_trial_balance.rml',
parser=aged_trial_report, header=False)

View File

@ -33,42 +33,42 @@ import datetime
import operator
class budget_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(budget_report, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'lines': self.lines,
'budget_total': self.budget_total,
'post_total': self.post_total,
'time': time,
})
def __init__(self, cr, uid, name, context):
super(budget_report, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'lines': self.lines,
'budget_total': self.budget_total,
'post_total': self.post_total,
'time': time,
})
def post_total(self, post_obj, date1, date2):
def str2date(date_str):
return datetime.date.fromtimestamp(time.mktime(time.strptime(date_str, '%Y-%m-%d')))
def interval(d1str, d2str):
return (str2date(d2str) - str2date(d1str) + datetime.timedelta(days=1)).days
prev = reduce(lambda x,d: x + d.amount, post_obj.dotation_ids, 0.0)
period_days = interval(date1, date2)
for d in post_obj.dotation_ids:
i = interval(d.period_id.date_start, d.period_id.date_stop)
total_days = reduce(lambda x,d: x+interval(d.period_id.date_start, d.period_id.date_stop), post_obj.dotation_ids, 0)
achievements = reduce(lambda x,l: x+l['achievements'], self.lines(post_obj, date1, date2), 0.0)
return [{'prev': prev, 'prev_period': prev * period_days / total_days, 'achievements': achievements}]
def post_total(self, post_obj, date1, date2):
def str2date(date_str):
return datetime.date.fromtimestamp(time.mktime(time.strptime(date_str, '%Y-%m-%d')))
def interval(d1str, d2str):
return (str2date(d2str) - str2date(d1str) + datetime.timedelta(days=1)).days
prev = reduce(lambda x,d: x + d.amount, post_obj.dotation_ids, 0.0)
period_days = interval(date1, date2)
for d in post_obj.dotation_ids:
i = interval(d.period_id.date_start, d.period_id.date_stop)
total_days = reduce(lambda x,d: x+interval(d.period_id.date_start, d.period_id.date_stop), post_obj.dotation_ids, 0)
achievements = reduce(lambda x,l: x+l['achievements'], self.lines(post_obj, date1, date2), 0.0)
return [{'prev': prev, 'prev_period': prev * period_days / total_days, 'achievements': achievements}]
def budget_total(self, post_objs, date1, date2):
res = {'prev': 0.0, 'prev_period': 0.0, 'achievements': 0.0}
for post_obj in post_objs:
r = self.post_total(post_obj, date1, date2)[0]
for k in r:
res[k] += r[k]
return [res]
def budget_total(self, post_objs, date1, date2):
res = {'prev': 0.0, 'prev_period': 0.0, 'achievements': 0.0}
for post_obj in post_objs:
r = self.post_total(post_obj, date1, date2)[0]
for k in r:
res[k] += r[k]
return [res]
def lines(self, post_obj, date1, date2):
res = []
for a in post_obj.account_ids:
self.cr.execute("SELECT COALESCE(SUM(debit-credit), 0) FROM account_move_line WHERE account_id=%d AND date>=%s AND date<=%s and state<>'draft'", (a.id, date1, date2))
achievements = float(self.cr.fetchone()[0]) * (post_obj.sens=='produit' and -1 or 1)
res.append({'name': a.name, 'code': a.code, 'achievements': achievements})
return res
def lines(self, post_obj, date1, date2):
res = []
for a in post_obj.account_ids:
self.cr.execute("SELECT COALESCE(SUM(debit-credit), 0) FROM account_move_line WHERE account_id=%d AND date>=%s AND date<=%s and state<>'draft'", (a.id, date1, date2))
achievements = float(self.cr.fetchone()[0]) * (post_obj.sens=='produit' and -1 or 1)
res.append({'name': a.name, 'code': a.code, 'achievements': achievements})
return res
report_sxw.report_sxw('report.account.budget', 'account.budget.post', 'addons/account/report/budget_report.rml',parser=budget_report)

View File

@ -34,25 +34,25 @@ from report import report_sxw
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def lines(self, period_id, journal_id, *args):
self.cr.execute('select a.code, a.name, sum(debit) as debit, sum(credit) as credit from account_move_line l left join account_account a on (l.account_id=a.id) where l.period_id=%d and l.journal_id=%d and l.state<>\'draft\' group by a.id, a.code, a.name', (period_id, journal_id))
return self.cr.dictfetchall()
def lines(self, period_id, journal_id, *args):
self.cr.execute('select a.code, a.name, sum(debit) as debit, sum(credit) as credit from account_move_line l left join account_account a on (l.account_id=a.id) where l.period_id=%d and l.journal_id=%d and l.state<>\'draft\' group by a.id, a.code, a.name', (period_id, journal_id))
return self.cr.dictfetchall()
def _sum_debit(self, period_id, journal_id):
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, period_id, journal_id):
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, period_id, journal_id):
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, period_id, journal_id):
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id=%d and state<>\'draft\'', (period_id, journal_id))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.central.journal', 'account.journal.period', 'addons/account/report/central_journal.rml',parser=journal_print)

View File

@ -35,65 +35,65 @@ from report import report_sxw
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'periods': self.periods,
'sum_debit_period': self._sum_debit_period,
'sum_credit_period': self._sum_credit_period,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def __init__(self, cr, uid, name, context):
super(journal_print, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'periods': self.periods,
'sum_debit_period': self._sum_debit_period,
'sum_credit_period': self._sum_credit_period,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit
})
def preprocess(self, objects, datas, ids):
super(journal_print, self).preprocess(objects, datas, ids)
self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')')
res = self.cr.fetchall()
self.period_ids = ','.join([str(x[0]) for x in res])
self.journal_ids = ','.join([str(x[1]) for x in res])
def preprocess(self, objects, datas, ids):
super(journal_print, self).preprocess(objects, datas, ids)
self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')')
res = self.cr.fetchall()
self.period_ids = ','.join([str(x[0]) for x in res])
self.journal_ids = ','.join([str(x[1]) for x in res])
# returns a list of period objs
def periods(self, journal_period_objs):
dic = {}
def filter_unique(o):
key = o.period_id.id
res = key in dic
if not res:
dic[key] = True
return not res
filtered_objs = filter(filter_unique, journal_period_objs)
return map(lambda x: x.period_id, filtered_objs)
# returns a list of period objs
def periods(self, journal_period_objs):
dic = {}
def filter_unique(o):
key = o.period_id.id
res = key in dic
if not res:
dic[key] = True
return not res
filtered_objs = filter(filter_unique, journal_period_objs)
return map(lambda x: x.period_id, filtered_objs)
def lines(self, period_id):
if not self.journal_ids:
return []
self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%d and journal_id in (' + self.journal_ids + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,))
return self.cr.dictfetchall()
def lines(self, period_id):
if not self.journal_ids:
return []
self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%d and journal_id in (' + self.journal_ids + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,))
return self.cr.dictfetchall()
def _sum_debit_period(self, period_id):
if not self.journal_ids:
return 0.0
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,))
return self.cr.fetchone()[0] or 0.0
def _sum_debit_period(self, period_id):
if not self.journal_ids:
return 0.0
self.cr.execute('select sum(debit) from account_move_line where period_id=%d and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_period(self, period_id):
if not self.journal_ids:
return 0.0
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_period(self, period_id):
if not self.journal_ids:
return 0.0
self.cr.execute('select sum(credit) from account_move_line where period_id=%d and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.journal_ids or not self.period_ids:
return 0.0
self.cr.execute('select sum(debit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'')
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.journal_ids or not self.period_ids:
return 0.0
self.cr.execute('select sum(debit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'')
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.journal_ids or not self.period_ids:
return 0.0
self.cr.execute('select sum(credit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'')
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.journal_ids or not self.period_ids:
return 0.0
self.cr.execute('select sum(credit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'')
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print)

View File

@ -32,139 +32,139 @@ from report import report_sxw
import pooler
class general_ledger(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(general_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_account': self._sum_debit_account,
'sum_credit_account': self._sum_credit_account,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
def __init__(self, cr, uid, name, context):
super(general_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_account': self._sum_debit_account,
'sum_credit_account': self._sum_credit_account,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
})
self.context = context
self.tmp_list2=[]
self.final_list=[]
})
self.context = context
self.tmp_list2=[]
self.final_list=[]
def recur(self,list1):
tmp_list3 =list1
self.tmp_list2 =list1
# print "self list",self.tmp_list2
for i in range(0,len(list1)):
if list1[i] in self.final_list:
continue
self.final_list.append(list1[i])
# print "finallly",self.final_list
if list1[i].child_id:
def recur(self,list1):
tmp_list3 =list1
self.tmp_list2 =list1
# print "self list",self.tmp_list2
for i in range(0,len(list1)):
if list1[i] in self.final_list:
continue
self.final_list.append(list1[i])
# print "finallly",self.final_list
if list1[i].child_id:
tmp_list4=(hasattr(list1[i],'child_id') and list(list1[i].child_id) or [])
tmp_list4=(hasattr(list1[i],'child_id') and list(list1[i].child_id) or [])
self.tmp_list2 +=tmp_list4
self.tmp_list2 +=tmp_list4
self.tmp_list2+=self.recur(tmp_list4)
self.tmp_list2+=self.recur(tmp_list4)
return self.final_list
return self.final_list
def repeatIn(self, lst, name,nodes_parent=False):
def repeatIn(self, lst, name,nodes_parent=False):
if name=='o':
list_final=[]
if not lst:
return super(general_ledger,self).repeatIn(lst, name,nodes_parent)
try:
tmp_list = list(lst)
if tmp_list:
tmp_list = self.recur(tmp_list)
else:
return super(general_ledger,self).repeatIn(lst, name,nodes_parent)
if name=='o':
list_final=[]
if not lst:
return super(general_ledger,self).repeatIn(lst, name,nodes_parent)
try:
tmp_list = list(lst)
if tmp_list:
tmp_list = self.recur(tmp_list)
else:
return super(general_ledger,self).repeatIn(lst, name,nodes_parent)
lst = list(set([x for x in tmp_list]))
lst = list(set([x for x in tmp_list]))
final={}
# for x in lst:
# final[x]=x.id
# final1=sorted(final.items(), lambda x, y: cmp(x[1], y[1]))
final={}
# for x in lst:
# final[x]=x.id
# final1=sorted(final.items(), lambda x, y: cmp(x[1], y[1]))
#
# for a in final1:
# list_final.append(a[0])
list_final=tmp_list
# for a in final1:
# list_final.append(a[0])
list_final=tmp_list
except:
pass
else:
except:
pass
else:
list_final=lst
ret_data = super(general_ledger,self).repeatIn(list_final, name,nodes_parent)
list_final=lst
ret_data = super(general_ledger,self).repeatIn(list_final, name,nodes_parent)
return ret_data
return ret_data
def lines(self, account, form):
def lines(self, account, form):
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit "\
"FROM account_move_line l, account_journal j "\
"WHERE l.journal_id = j.id "\
"AND account_id = %d AND "+query+" "\
"ORDER by l.id", (account.id,))
res = self.cr.dictfetchall()
sum = 0.0
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit "\
"FROM account_move_line l, account_journal j "\
"WHERE l.journal_id = j.id "\
"AND account_id = %d AND "+query+" "\
"ORDER by l.id", (account.id,))
res = self.cr.dictfetchall()
sum = 0.0
for l in res:
sum += l['debit'] - l ['credit']
l['progress'] = sum
self.ids +=[account.id]
return res
for l in res:
sum += l['debit'] - l ['credit']
l['progress'] = sum
self.ids +=[account.id]
return res
def _sum_debit_account(self, account, form):
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(debit) "\
"FROM account_move_line l "\
"WHERE l.account_id = %d AND "+query, (account.id,))
return self.cr.fetchone()[0] or 0.0
def _sum_debit_account(self, account, form):
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(debit) "\
"FROM account_move_line l "\
"WHERE l.account_id = %d AND "+query, (account.id,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_account(self, account, form):
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(credit) "\
"FROM account_move_line l "\
"WHERE l.account_id = %d AND "+query, (account.id,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_account(self, account, form):
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(credit) "\
"FROM account_move_line l "\
"WHERE l.account_id = %d AND "+query, (account.id,))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self, form):
if not self.ids:
return 0.0
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(debit) "\
"FROM account_move_line l "\
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
def _sum_debit(self, form):
if not self.ids:
return 0.0
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(debit) "\
"FROM account_move_line l "\
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
return self.cr.fetchone()[0] or 0.0
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, form):
if not self.ids:
return 0.0
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(credit) "\
"FROM account_move_line l "\
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, form):
if not self.ids:
return 0.0
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear']
ctx['periods'] = form['periods'][0][2]
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
self.cr.execute("SELECT sum(credit) "\
"FROM account_move_line l "\
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.general.ledger', 'account.account', 'addons/account/report/general_ledger.rml', parser=general_ledger, header=False)

View File

@ -31,15 +31,15 @@ import time
from report import report_sxw
class account_invoice(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_invoice, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
})
def __init__(self, cr, uid, name, context):
super(account_invoice, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
})
report_sxw.report_sxw(
'report.account.invoice',
'account.invoice',
'addons/account/report/invoice.rml',
parser=account_invoice,
)
'report.account.invoice',
'account.invoice',
'addons/account/report/invoice.rml',
parser=account_invoice,
)

View File

@ -35,30 +35,30 @@ from report import report_sxw
import pooler
class Overdue(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(Overdue, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time' : time,
'adr_get' : self._adr_get,
'getLines' : self._lines_get,
})
def __init__(self, cr, uid, name, context):
super(Overdue, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time' : time,
'adr_get' : self._adr_get,
'getLines' : self._lines_get,
})
def _adr_get(self, partner, type):
res_partner = pooler.get_pool(self.cr.dbname).get('res.partner')
res_partner_address = pooler.get_pool(self.cr.dbname).get('res.partner.address')
addresses = res_partner.address_get(self.cr, self.uid, [partner.id], [type])
adr_id = addresses and addresses[type] or False
return adr_id and res_partner_address.read(self.cr, self.uid, [adr_id])[0] or False
def _adr_get(self, partner, type):
res_partner = pooler.get_pool(self.cr.dbname).get('res.partner')
res_partner_address = pooler.get_pool(self.cr.dbname).get('res.partner.address')
addresses = res_partner.address_get(self.cr, self.uid, [partner.id], [type])
adr_id = addresses and addresses[type] or False
return adr_id and res_partner_address.read(self.cr, self.uid, [adr_id])[0] or False
def _lines_get(self, partner):
moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
movelines = moveline_obj.search(self.cr, self.uid,
[('partner_id', '=', partner.id),
('account_id.type', 'in', ['receivable', 'payable']),
('state', '<>', 'draft'), ('reconcile_id', '=', False)])
movelines = moveline_obj.browse(self.cr, self.uid, movelines)
return movelines
def _lines_get(self, partner):
moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
movelines = moveline_obj.search(self.cr, self.uid,
[('partner_id', '=', partner.id),
('account_id.type', 'in', ['receivable', 'payable']),
('state', '<>', 'draft'), ('reconcile_id', '=', False)])
movelines = moveline_obj.browse(self.cr, self.uid, movelines)
return movelines
report_sxw.report_sxw('report.account.overdue', 'res.partner',
'addons/account/report/overdue.rml', parser=Overdue)
'addons/account/report/overdue.rml', parser=Overdue)

View File

@ -32,201 +32,201 @@ import time
from report import report_sxw
class partner_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(partner_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_litige': self._sum_litige,
'sum_sdebit': self._sum_sdebit,
'sum_scredit': self._sum_scredit,
'solde_debit': self._solde_balance_debit,
'solde_credit': self._solde_balance_credit,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def __init__(self, cr, uid, name, context):
super(partner_balance, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'sum_litige': self._sum_litige,
'sum_sdebit': self._sum_sdebit,
'sum_scredit': self._sum_scredit,
'solde_debit': self._solde_balance_debit,
'solde_credit': self._solde_balance_credit,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def preprocess(self, objects, data, ids):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute('SELECT DISTINCT line.partner_id ' \
'FROM account_move_line AS line, account_account AS account ' \
'WHERE line.partner_id IS NOT NULL ' \
'AND line.date >= %s ' \
'AND line.date <= %s ' \
'AND ' + line_query + ' ' \
'AND line.account_id = account.id ' \
'AND account.company_id = %d ' \
'AND account.active',
(data['form']['date1'], data['form']['date2'],
data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute('SELECT a.id ' \
'FROM account_account a ' \
'LEFT JOIN account_account_type t ' \
'ON (a.type = t.code) ' \
'WHERE t.partner_account = TRUE ' \
'AND a.company_id = %d ' \
'AND a.active', (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(partner_balance, self).preprocess(objects, data, new_ids)
def preprocess(self, objects, data, ids):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute('SELECT DISTINCT line.partner_id ' \
'FROM account_move_line AS line, account_account AS account ' \
'WHERE line.partner_id IS NOT NULL ' \
'AND line.date >= %s ' \
'AND line.date <= %s ' \
'AND ' + line_query + ' ' \
'AND line.account_id = account.id ' \
'AND account.company_id = %d ' \
'AND account.active',
(data['form']['date1'], data['form']['date2'],
data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute('SELECT a.id ' \
'FROM account_account a ' \
'LEFT JOIN account_account_type t ' \
'ON (a.type = t.code) ' \
'WHERE t.partner_account = TRUE ' \
'AND a.company_id = %d ' \
'AND a.active', (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(partner_balance, self).preprocess(objects, data, new_ids)
def lines(self):
if not self.partner_ids:
return []
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \
"CASE WHEN sum(debit) > sum(credit) " \
"THEN sum(debit) - sum(credit) " \
"ELSE 0 " \
"END AS sdebit, " \
"CASE WHEN sum(debit) < sum(credit) " \
"THEN sum(credit) - sum(debit) " \
"ELSE 0 " \
"END AS scredit, " \
"(SELECT sum(debit-credit) " \
"FROM account_move_line l " \
"WHERE partner_id = p.id " \
"AND date >= %s " \
"AND date <= %s " \
"AND blocked = TRUE " \
"AND " + line_query + " " \
") AS enlitige " \
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND l.date >= %s " \
"AND l.date <= %s " \
"AND " + line_query + " " \
"GROUP BY p.id, p.ref, p.name " \
"ORDER BY p.ref, p.name",
(self.datas['form']['date1'], self.datas['form']['date2'],
self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
return res
def lines(self):
if not self.partner_ids:
return []
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \
"CASE WHEN sum(debit) > sum(credit) " \
"THEN sum(debit) - sum(credit) " \
"ELSE 0 " \
"END AS sdebit, " \
"CASE WHEN sum(debit) < sum(credit) " \
"THEN sum(credit) - sum(debit) " \
"ELSE 0 " \
"END AS scredit, " \
"(SELECT sum(debit-credit) " \
"FROM account_move_line l " \
"WHERE partner_id = p.id " \
"AND date >= %s " \
"AND date <= %s " \
"AND blocked = TRUE " \
"AND " + line_query + " " \
") AS enlitige " \
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND l.date >= %s " \
"AND l.date <= %s " \
"AND " + line_query + " " \
"GROUP BY p.id, p.ref, p.name " \
"ORDER BY p.ref, p.name",
(self.datas['form']['date1'], self.datas['form']['date2'],
self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
return res
def _sum_debit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(debit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >=%s ' \
'AND date <= %s ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(debit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >=%s ' \
'AND date <= %s ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(credit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(credit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_litige(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(debit-credit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND blocked=TRUE ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_litige(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT sum(debit-credit) ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND blocked=TRUE ' \
'AND ' + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_sdebit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT CASE WHEN sum(debit) > sum(credit) ' \
'THEN sum(debit - credit) ' \
'ELSE 0 ' \
'END ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query + ' ' \
'GROUP BY partner_id',
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_sdebit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT CASE WHEN sum(debit) > sum(credit) ' \
'THEN sum(debit - credit) ' \
'ELSE 0 ' \
'END ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query + ' ' \
'GROUP BY partner_id',
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_scredit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT CASE WHEN sum(debit) < sum(credit) ' \
'THEN sum(credit - debit) ' \
'ELSE 0 ' \
'END ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query + ' ' \
'GROUP BY partner_id',
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_scredit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
'SELECT CASE WHEN sum(debit) < sum(credit) ' \
'THEN sum(credit - debit) ' \
'ELSE 0 ' \
'END ' \
'FROM account_move_line ' \
'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
'AND date >= %s ' \
'AND date <= %s ' \
'AND ' + line_query + ' ' \
'GROUP BY partner_id',
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _solde_balance_debit(self):
debit, credit = self._sum_debit(), self._sum_credit()
return debit > credit and debit - credit
def _solde_balance_debit(self):
debit, credit = self._sum_debit(), self._sum_credit()
return debit > credit and debit - credit
def _solde_balance_credit(self):
debit, credit = self._sum_debit(), self._sum_credit()
return credit > debit and credit - debit
def _solde_balance_credit(self):
debit, credit = self._sum_debit(), self._sum_credit()
return credit > debit and credit - debit
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw('report.account.partner.balance', 'res.partner',
'addons/account/report/partner_balance.rml',parser=partner_balance,
header=False)
'addons/account/report/partner_balance.rml',parser=partner_balance,
header=False)

View File

@ -33,85 +33,85 @@ from report import report_sxw
class tax_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(tax_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'get_period': self._get_period,
'get_codes': self._get_codes,
'get_general': self._get_general,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def __init__(self, cr, uid, name, context):
super(tax_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'get_period': self._get_period,
'get_codes': self._get_codes,
'get_general': self._get_general,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def _add_header(self, node):
return True
def _add_header(self, node):
return True
def _get_period(self, period_id):
return self.pool.get('account.period').browse(self.cr, self.uid, period_id).name
def _get_period(self, period_id):
return self.pool.get('account.period').browse(self.cr, self.uid, period_id).name
def _get_general(self, tax_code_id, period_id, company_id, based_on):
res=[]
if based_on == 'payments':
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
SUM(line.debit) AS debit, \
SUM(line.credit) AS credit, \
COUNT(*) AS count, \
account.id AS account_id \
FROM account_move_line AS line, \
account_account AS account, \
account_move AS move \
LEFT JOIN account_invoice invoice ON \
(invoice.move_id = move.id) \
WHERE line.state<>%s \
AND line.period_id = %d \
AND line.tax_code_id = %d \
AND line.account_id = account.id \
AND account.company_id = %d \
AND move.id = line.move_id \
AND ((invoice.state = %s) \
OR (invoice.id IS NULL)) \
GROUP BY account.id', ('draft', period_id, tax_code_id,
company_id, 'paid'))
else :
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
SUM(line.debit) AS debit, \
SUM(line.credit) AS credit, \
COUNT(*) AS count, \
account.id AS account_id \
FROM account_move_line AS line, \
account_account AS account \
WHERE line.state <> %s \
AND line.period_id = %d \
AND line.tax_code_id = %d \
AND line.account_id = account.id \
AND account.company_id = %d \
AND account.active \
GROUP BY account.id', ('draft', period_id, tax_code_id,
company_id))
res = self.cr.dictfetchall()
i = 0
while i<len(res):
res[i]['account'] = self.pool.get('account.account').browse(self.cr, self.uid, res[i]['account_id'])
i+=1
return res
def _get_general(self, tax_code_id, period_id, company_id, based_on):
res=[]
if based_on == 'payments':
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
SUM(line.debit) AS debit, \
SUM(line.credit) AS credit, \
COUNT(*) AS count, \
account.id AS account_id \
FROM account_move_line AS line, \
account_account AS account, \
account_move AS move \
LEFT JOIN account_invoice invoice ON \
(invoice.move_id = move.id) \
WHERE line.state<>%s \
AND line.period_id = %d \
AND line.tax_code_id = %d \
AND line.account_id = account.id \
AND account.company_id = %d \
AND move.id = line.move_id \
AND ((invoice.state = %s) \
OR (invoice.id IS NULL)) \
GROUP BY account.id', ('draft', period_id, tax_code_id,
company_id, 'paid'))
else :
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
SUM(line.debit) AS debit, \
SUM(line.credit) AS credit, \
COUNT(*) AS count, \
account.id AS account_id \
FROM account_move_line AS line, \
account_account AS account \
WHERE line.state <> %s \
AND line.period_id = %d \
AND line.tax_code_id = %d \
AND line.account_id = account.id \
AND account.company_id = %d \
AND account.active \
GROUP BY account.id', ('draft', period_id, tax_code_id,
company_id))
res = self.cr.dictfetchall()
i = 0
while i<len(res):
res[i]['account'] = self.pool.get('account.account').browse(self.cr, self.uid, res[i]['account_id'])
i+=1
return res
def _get_codes(self, period_id, based_on, parent=False, level=0):
tc = self.pool.get('account.tax.code')
ids = tc.search(self.cr, self.uid, [('parent_id','=',parent)])
res = []
for code in tc.browse(self.cr, self.uid, ids, {'period_id': period_id,
'based_on': based_on}):
res.append((' - '*level*2, code))
res += self._get_codes(period_id, based_on, code.id, level+1)
return res
def _get_codes(self, period_id, based_on, parent=False, level=0):
tc = self.pool.get('account.tax.code')
ids = tc.search(self.cr, self.uid, [('parent_id','=',parent)])
res = []
for code in tc.browse(self.cr, self.uid, ids, {'period_id': period_id,
'based_on': based_on}):
res.append((' - '*level*2, code))
res += self._get_codes(period_id, based_on, code.id, level+1)
return res
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw('report.account.vat.declaration', 'account.tax.code',
'addons/account/report/tax_report.rml', parser=tax_report, header=False)
'addons/account/report/tax_report.rml', parser=tax_report, header=False)

View File

@ -32,147 +32,147 @@ import time
from report import report_sxw
class third_party_ledger(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(third_party_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_partner': self._sum_debit_partner,
'sum_credit_partner': self._sum_credit_partner,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def __init__(self, cr, uid, name, context):
super(third_party_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_partner': self._sum_debit_partner,
'sum_credit_partner': self._sum_credit_partner,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def preprocess(self, objects, data, ids):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute(
"SELECT DISTINCT line.partner_id " \
"FROM account_move_line AS line, account_account AS account " \
"WHERE line.partner_id IS NOT NULL " \
"AND line.date >= %s " \
"AND line.date <= %s " \
"AND " + line_query + " " \
"AND line.account_id = account.id " \
"AND account.company_id = %d " \
"AND account.active",
(data['form']['date1'], data['form']['date2'],
data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute(
"SELECT a.id " \
"FROM account_account a " \
"LEFT JOIN account_account_type t " \
"ON (a.type=t.code) " \
"WHERE t.partner_account=TRUE " \
"AND a.company_id = %d " \
"AND a.active", (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(third_party_ledger, self).preprocess(objects, data, new_ids)
def preprocess(self, objects, data, ids):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute(
"SELECT DISTINCT line.partner_id " \
"FROM account_move_line AS line, account_account AS account " \
"WHERE line.partner_id IS NOT NULL " \
"AND line.date >= %s " \
"AND line.date <= %s " \
"AND " + line_query + " " \
"AND line.account_id = account.id " \
"AND account.company_id = %d " \
"AND account.active",
(data['form']['date1'], data['form']['date2'],
data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute(
"SELECT a.id " \
"FROM account_account a " \
"LEFT JOIN account_account_type t " \
"ON (a.type=t.code) " \
"WHERE t.partner_account=TRUE " \
"AND a.company_id = %d " \
"AND a.active", (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(third_party_ledger, self).preprocess(objects, data, new_ids)
def lines(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \
"FROM account_move_line l " \
"LEFT JOIN account_journal j " \
"ON (l.journal_id = j.id) " \
"WHERE l.partner_id = %d " \
"AND l.account_id IN (" + self.account_ids + ") " \
"AND l.date >= %s " \
"AND l.date <= %s "
"AND " + line_query + " " \
"ORDER BY l.id",
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
sum = 0.0
for r in res:
sum += r['debit'] - r['credit']
r['progress'] = sum
return res
def lines(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \
"FROM account_move_line l " \
"LEFT JOIN account_journal j " \
"ON (l.journal_id = j.id) " \
"WHERE l.partner_id = %d " \
"AND l.account_id IN (" + self.account_ids + ") " \
"AND l.date >= %s " \
"AND l.date <= %s "
"AND " + line_query + " " \
"ORDER BY l.id",
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
sum = 0.0
for r in res:
sum += r['debit'] - r['credit']
r['progress'] = sum
return res
def _sum_debit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id = %d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_debit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id = %d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id=%d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas["form"]["date1"], self.datas["form"]["date2"]))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id=%d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas["form"]["date1"], self.datas["form"]["date2"]))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw('report.account.third_party_ledger', 'res.partner',
'addons/account/report/third_party_ledger.rml',parser=third_party_ledger,
header=False)
'addons/account/report/third_party_ledger.rml',parser=third_party_ledger,
header=False)

View File

@ -32,35 +32,35 @@ import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="fiscalyear" colspan="4"/>
<field name="periods" colspan="4"/>
<field name="fiscalyear" colspan="4"/>
<field name="periods" colspan="4"/>
</form>'''
dates_fields = {
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
data['form']['target_move'] = False
if context.has_key('target_move'):
data['form']['target_move'] = context['target_move']
return data['form']
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
data['form']['target_move'] = False
if context.has_key('target_move'):
data['form']['target_move'] = context['target_move']
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.account.balance', 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.account.balance', 'state':'end'}
}
}
wizard_report('account.account.balance.report')

View File

@ -31,52 +31,52 @@ import wizard
import pooler
class wizard_account_chart(wizard.interface):
_account_chart_arch = '''<?xml version="1.0"?>
<form string="Account charts">
<field name="fiscalyear"/>
<field name="target_move"/>
</form>'''
_account_chart_arch = '''<?xml version="1.0"?>
<form string="Account charts">
<field name="fiscalyear"/>
<field name="target_move"/>
</form>'''
_account_chart_fields = {
'fiscalyear': {
'string': 'Fiscal year',
'type': 'many2one',
'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year',
},
'target_move': {
'string': 'Target Moves',
'type': 'selection',
'selection': [('all','All Entries'),('posted_only','All Posted Entries')],
'required': True,
'default': lambda *a:"all",
},
}
_account_chart_fields = {
'fiscalyear': {
'string': 'Fiscal year',
'type': 'many2one',
'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year',
},
'target_move': {
'string': 'Target Moves',
'type': 'selection',
'selection': [('all','All Entries'),('posted_only','All Posted Entries')],
'required': True,
'default': lambda *a:"all",
},
}
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
return data['form']
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
return data['form']
def _account_chart_open_window(self, cr, uid, data, context):
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
def _account_chart_open_window(self, cr, uid, data, context):
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
result['context'] = str({'fiscalyear': data['form']['fiscalyear'],'target_move':data['form']['target_move']})
return result
result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
result['context'] = str({'fiscalyear': data['form']['fiscalyear'],'target_move':data['form']['target_move']})
return result
states = {
'init': {
'actions': [_get_defaults],
'result': {'type': 'form', 'arch':_account_chart_arch, 'fields':_account_chart_fields, 'state': [('end', 'Cancel'), ('open', 'Open Charts')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action':_account_chart_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type': 'form', 'arch':_account_chart_arch, 'fields':_account_chart_fields, 'state': [('end', 'Cancel'), ('open', 'Open Charts')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action':_account_chart_open_window, 'state':'end'}
}
}
wizard_account_chart('account.chart')

View File

@ -32,27 +32,27 @@ import pooler
duplicate_form = '''<?xml version="1.0"?>
<form string="Duplicate account charts">
<field name="company_id"/>
<field name="company_id"/>
</form>'''
duplicate_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
}
def _do_duplicate(self, cr, uid, data, context):
account_obj = pooler.get_pool(cr.dbname).get('account.account')
account_obj.copy(cr, uid, data['id'], data['form'], context=context)
return {}
account_obj = pooler.get_pool(cr.dbname).get('account.account')
account_obj.copy(cr, uid, data['id'], data['form'], context=context)
return {}
class wizard_account_duplicate(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': duplicate_form, 'fields': duplicate_fields, 'state': (('end', 'Cancel'), ('duplicate', 'Duplicate'))},
},
'duplicate': {
'actions': [_do_duplicate],
'result': {'type': 'state', 'state': 'end'},
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': duplicate_form, 'fields': duplicate_fields, 'state': (('end', 'Cancel'), ('duplicate', 'Duplicate'))},
},
'duplicate': {
'actions': [_do_duplicate],
'result': {'type': 'state', 'state': 'end'},
},
}
wizard_account_duplicate('account.wizard.account.duplicate')

View File

@ -37,67 +37,67 @@ from tools.translate import _
_aged_trial_form = """<?xml version="1.0"?>
<form string="Aged Trial Balance">
<field name="company_id"/>
<newline/>
<field name="fiscalyear"/>
<newline/>
<field name="period_length"/>
<newline/>
<field name="sorting_on"/>
<newline/>
<field name="computation"/>
<field name="company_id"/>
<newline/>
<field name="fiscalyear"/>
<newline/>
<field name="period_length"/>
<newline/>
<field name="sorting_on"/>
<newline/>
<field name="computation"/>
</form>"""
_aged_trial_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'period_length': {'string': 'Period length (days)', 'type': 'integer', 'required': True, 'default': lambda *a:30},
'sorting_on':{'string': 'Sorting On', 'type': 'selection', 'selection': [('partner','By Partner Name (asc)'), ('amount','By Amount (desc)')],'required': True, 'default': lambda *a:'partner'},
'computation':{'string': 'Computational Method', 'type': 'selection', 'selection': [("\'receivable\'",'On Receivables Only'), ("\'payable\'",'On Payables Only'), ("\'receivable\',\'payable\'",'On Receivables & Payables')], 'required': True, 'default': lambda *a:"\'receivable\'"}
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'period_length': {'string': 'Period length (days)', 'type': 'integer', 'required': True, 'default': lambda *a:30},
'sorting_on':{'string': 'Sorting On', 'type': 'selection', 'selection': [('partner','By Partner Name (asc)'), ('amount','By Amount (desc)')],'required': True, 'default': lambda *a:'partner'},
'computation':{'string': 'Computational Method', 'type': 'selection', 'selection': [("\'receivable\'",'On Receivables Only'), ("\'payable\'",'On Payables Only'), ("\'receivable\',\'payable\'",'On Receivables & Payables')], 'required': True, 'default': lambda *a:"\'receivable\'"}
}
def _calc_dates(self, cr, uid, data, context):
res = {}
period_length = data['form']['period_length']
if period_length<=0:
raise wizard.except_wizard(_('UserError'), _('You must enter a period length that cannot be 0 or below !'))
start = now()
for i in range(5)[::-1]:
stop = start-RelativeDateTime(days=period_length)
res[str(i)] = {
'name' : str((5-i)*period_length)+' days',
'stop': start.strftime('%Y-%m-%d'),
'start' : stop.strftime('%Y-%m-%d'),
}
start = stop - RelativeDateTime(days=1)
return res
res = {}
period_length = data['form']['period_length']
if period_length<=0:
raise wizard.except_wizard(_('UserError'), _('You must enter a period length that cannot be 0 or below !'))
start = now()
for i in range(5)[::-1]:
stop = start-RelativeDateTime(days=period_length)
res[str(i)] = {
'name' : str((5-i)*period_length)+' days',
'stop': start.strftime('%Y-%m-%d'),
'start' : stop.strftime('%Y-%m-%d'),
}
start = stop - RelativeDateTime(days=1)
return res
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':_aged_trial_form, 'fields':_aged_trial_fields, 'state':[('end','Cancel'),('print','Print Aged Partner Balance')]},
},
'print': {
'actions': [_calc_dates],
'result': {'type':'print', 'report':'account.aged.trial.balance', 'state':'end'},
},
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':_aged_trial_form, 'fields':_aged_trial_fields, 'state':[('end','Cancel'),('print','Print Aged Partner Balance')]},
},
'print': {
'actions': [_calc_dates],
'result': {'type':'print', 'report':'account.aged.trial.balance', 'state':'end'},
},
}
wizard_report('account.aged.trial.balance')

View File

@ -40,11 +40,11 @@ import time
# - journal
# - compte d'ajustement
# - montant max (0,03)
# <field name="max_amount"/>
# <field name="max_amount"/>
# - libelle write-off
# - devise principale ou secondaire
# devise secondaire = amount_currency
# si devise: pas prendre ceux avec montant_devise = 0
# devise secondaire = amount_currency
# si devise: pas prendre ceux avec montant_devise = 0
# a demander à fabien:
# - checkbox (comme ds sage) "lettrage rapide des comptes soldés"?
@ -54,273 +54,273 @@ import time
_reconcile_form = '''<?xml version="1.0"?>
<form string="Reconciliation">
<separator string="Options" colspan="4"/>
<field name="account_ids" colspan="4" domain="[('reconcile','=',1)]" views="account.view_account_list">
</field>
<field name="date1"/>
<field name="date2"/>
<field name="power"/>
<separator string="Write-Off Move" colspan="4"/>
<field name="max_amount"/>
<field name="writeoff_acc_id"/>
<field name="journal_id"/>
<field name="period_id"/>
<separator string="Options" colspan="4"/>
<field name="account_ids" colspan="4" domain="[('reconcile','=',1)]" views="account.view_account_list">
</field>
<field name="date1"/>
<field name="date2"/>
<field name="power"/>
<separator string="Write-Off Move" colspan="4"/>
<field name="max_amount"/>
<field name="writeoff_acc_id"/>
<field name="journal_id"/>
<field name="period_id"/>
</form>'''
_reconcile_fields = {
'account_ids': {
'string': 'Account to reconcile',
'type': 'many2many',
'relation': 'account.account',
'domain': [('reconcile','=',1)],
'required': True
},
'writeoff_acc_id': {
'string': 'Account',
'type': 'many2one',
'relation': 'account.account',
'required': True
},
'journal_id': {
'string': 'Journal',
'type': 'many2one',
'relation': 'account.journal',
'required': True
},
'period_id': {
'string': 'Period',
'type': 'many2one',
'relation': 'account.period',
'required': True
},
'max_amount': {
'string': 'Maximum write-off amount',
'type': 'float',
},
#'currency': {
# 'string': 'Reconcile in',
# 'type': 'selection',
# 'selection': [('current','current currency'), ('secondary','secondary currency')],
# 'required': True
#},
'power': {
'string': 'Power',
'type': 'selection',
'selection': [(p,str(p)) for p in range(2, 10)],
'required': True
},
'date1': {
'string': 'Start of period',
'type': 'date',
'required': True,
'default': lambda *a: time.strftime('%Y-01-01')
},
'date2': {
'string': 'End of period',
'type': 'date',
'required': True,
'default': lambda *a: time.strftime('%Y-%m-%d')
},
'account_ids': {
'string': 'Account to reconcile',
'type': 'many2many',
'relation': 'account.account',
'domain': [('reconcile','=',1)],
'required': True
},
'writeoff_acc_id': {
'string': 'Account',
'type': 'many2one',
'relation': 'account.account',
'required': True
},
'journal_id': {
'string': 'Journal',
'type': 'many2one',
'relation': 'account.journal',
'required': True
},
'period_id': {
'string': 'Period',
'type': 'many2one',
'relation': 'account.period',
'required': True
},
'max_amount': {
'string': 'Maximum write-off amount',
'type': 'float',
},
#'currency': {
# 'string': 'Reconcile in',
# 'type': 'selection',
# 'selection': [('current','current currency'), ('secondary','secondary currency')],
# 'required': True
#},
'power': {
'string': 'Power',
'type': 'selection',
'selection': [(p,str(p)) for p in range(2, 10)],
'required': True
},
'date1': {
'string': 'Start of period',
'type': 'date',
'required': True,
'default': lambda *a: time.strftime('%Y-01-01')
},
'date2': {
'string': 'End of period',
'type': 'date',
'required': True,
'default': lambda *a: time.strftime('%Y-%m-%d')
},
}
_result_form = '''<?xml version="1.0"?>
<form string="Reconciliation result">
<field name="reconciled"/>
<newline/>
<field name="unreconciled"/>
<field name="reconciled"/>
<newline/>
<field name="unreconciled"/>
</form>'''
_result_fields = {
'reconciled': {
'string': 'Reconciled transactions',
'type': 'integer',
'readonly': True
},
'unreconciled': {
'string': 'Not reconciled transactions',
'type': 'integer',
'readonly': True
},
'reconciled': {
'string': 'Reconciled transactions',
'type': 'integer',
'readonly': True
},
'unreconciled': {
'string': 'Not reconciled transactions',
'type': 'integer',
'readonly': True
},
}
#TODO: cleanup and comment this code... For now, it is awfulllll
# (way too complex, and really slow)...
def do_reconcile(cr, uid, credits, debits, max_amount, power, writeoff_acc_id, period_id, journal_id, context={}):
# for one value of a credit, check all debits, and combination of them
# depending on the power. It starts with a power of one and goes up
# to the max power allowed
def check2(value, move_list, power):
def check(value, move_list, power):
for i in range(len(move_list)):
move = move_list[i]
if power == 1:
if abs(value - move[1]) <= max_amount + 0.00001:
return [move[0]]
else:
del move_list[i]
res = check(value - move[1], move_list, power-1)
move_list[i:i] = [move]
if res:
res.append(move[0])
return res
return False
# for one value of a credit, check all debits, and combination of them
# depending on the power. It starts with a power of one and goes up
# to the max power allowed
def check2(value, move_list, power):
def check(value, move_list, power):
for i in range(len(move_list)):
move = move_list[i]
if power == 1:
if abs(value - move[1]) <= max_amount + 0.00001:
return [move[0]]
else:
del move_list[i]
res = check(value - move[1], move_list, power-1)
move_list[i:i] = [move]
if res:
res.append(move[0])
return res
return False
for p in range(1, power+1):
res = check(value, move_list, p)
if res:
return res
return False
for p in range(1, power+1):
res = check(value, move_list, p)
if res:
return res
return False
# for a list of credit and debit and a given power, check if there
# are matching tuples of credit and debits, check all debits, and combination of them
# depending on the power. It starts with a power of one and goes up
# to the max power allowed
def check4(list1, list2, power):
def check3(value, list1, list2, list1power, power):
for i in range(len(list1)):
move = list1[i]
if list1power == 1:
res = check2(value + move[1], list2, power - 1)
if res:
return ([move[0]], res)
else:
del list1[i]
res = check3(value + move[1], list1, list2, list1power-1, power-1)
list1[i:i] = [move]
if res:
x, y = res
x.append(move[0])
return (x, y)
return False
# for a list of credit and debit and a given power, check if there
# are matching tuples of credit and debits, check all debits, and combination of them
# depending on the power. It starts with a power of one and goes up
# to the max power allowed
def check4(list1, list2, power):
def check3(value, list1, list2, list1power, power):
for i in range(len(list1)):
move = list1[i]
if list1power == 1:
res = check2(value + move[1], list2, power - 1)
if res:
return ([move[0]], res)
else:
del list1[i]
res = check3(value + move[1], list1, list2, list1power-1, power-1)
list1[i:i] = [move]
if res:
x, y = res
x.append(move[0])
return (x, y)
return False
for p in range(1, power):
res = check3(0, list1, list2, p, power)
if res:
return res
return False
for p in range(1, power):
res = check3(0, list1, list2, p, power)
if res:
return res
return False
def check5(list1, list2, max_power):
for p in range(2, max_power+1):
res = check4(list1, list2, p)
if res:
return res
def check5(list1, list2, max_power):
for p in range(2, max_power+1):
res = check4(list1, list2, p)
if res:
return res
ok = True
reconciled = 0
move_line_obj = pooler.get_pool(cr.dbname).get('account.move.line')
while credits and debits and ok:
res = check5(credits, debits, power)
if res:
move_line_obj.reconcile(cr, uid, res[0] + res[1], 'auto', writeoff_acc_id, period_id, journal_id, context)
reconciled += len(res[0]) + len(res[1])
credits = [(id, credit) for (id, credit) in credits if id not in res[0]]
debits = [(id, debit) for (id, debit) in debits if id not in res[1]]
else:
ok = False
return (reconciled, len(credits)+len(debits))
ok = True
reconciled = 0
move_line_obj = pooler.get_pool(cr.dbname).get('account.move.line')
while credits and debits and ok:
res = check5(credits, debits, power)
if res:
move_line_obj.reconcile(cr, uid, res[0] + res[1], 'auto', writeoff_acc_id, period_id, journal_id, context)
reconciled += len(res[0]) + len(res[1])
credits = [(id, credit) for (id, credit) in credits if id not in res[0]]
debits = [(id, debit) for (id, debit) in debits if id not in res[1]]
else:
ok = False
return (reconciled, len(credits)+len(debits))
def _reconcile(self, cr, uid, data, context):
service = netsvc.LocalService("object_proxy")
move_line_obj = pooler.get_pool(cr.dbname).get('account.move.line')
form = data['form']
max_amount = form.get('max_amount', 0.0)
power = form['power']
reconciled = unreconciled = 0
if not form['account_ids']:
return {'reconciled':0, 'unreconciled':[0]}
for account_id in form['account_ids'][0][2]:
service = netsvc.LocalService("object_proxy")
move_line_obj = pooler.get_pool(cr.dbname).get('account.move.line')
form = data['form']
max_amount = form.get('max_amount', 0.0)
power = form['power']
reconciled = unreconciled = 0
if not form['account_ids']:
return {'reconciled':0, 'unreconciled':[0]}
for account_id in form['account_ids'][0][2]:
# reconcile automatically all transactions from partners whose balance is 0
cr.execute(
"SELECT partner_id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"GROUP BY partner_id " \
"HAVING ABS(SUM(debit-credit)) < %f AND count(*)>0",
(account_id, max_amount))
partner_ids = [id for (id,) in cr.fetchall()]
# reconcile automatically all transactions from partners whose balance is 0
cr.execute(
"SELECT partner_id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"GROUP BY partner_id " \
"HAVING ABS(SUM(debit-credit)) < %f AND count(*)>0",
(account_id, max_amount))
partner_ids = [id for (id,) in cr.fetchall()]
for partner_id in partner_ids:
cr.execute(
"SELECT id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND state <> 'draft' " \
"AND reconcile_id IS NULL",
(account_id, partner_id))
line_ids = [id for (id,) in cr.fetchall()]
for partner_id in partner_ids:
cr.execute(
"SELECT id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND state <> 'draft' " \
"AND reconcile_id IS NULL",
(account_id, partner_id))
line_ids = [id for (id,) in cr.fetchall()]
if len(line_ids):
move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
reconciled += len(line_ids)
if len(line_ids):
move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
reconciled += len(line_ids)
# get the list of partners who have more than one unreconciled transaction
cr.execute(
"SELECT partner_id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"GROUP BY partner_id " \
"HAVING count(*)>1",
(account_id,))
partner_ids = [id for (id,) in cr.fetchall()]
#filter?
for partner_id in partner_ids:
# get the list of unreconciled 'debit transactions' for this partner
cr.execute(
"SELECT id, debit " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"AND debit > 0",
(account_id, partner_id))
debits = cr.fetchall()
# get the list of partners who have more than one unreconciled transaction
cr.execute(
"SELECT partner_id " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"GROUP BY partner_id " \
"HAVING count(*)>1",
(account_id,))
partner_ids = [id for (id,) in cr.fetchall()]
#filter?
for partner_id in partner_ids:
# get the list of unreconciled 'debit transactions' for this partner
cr.execute(
"SELECT id, debit " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"AND debit > 0",
(account_id, partner_id))
debits = cr.fetchall()
# get the list of unreconciled 'credit transactions' for this partner
cr.execute(
"SELECT id, credit " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"AND credit > 0",
(account_id, partner_id))
credits = cr.fetchall()
# get the list of unreconciled 'credit transactions' for this partner
cr.execute(
"SELECT id, credit " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND partner_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " \
"AND credit > 0",
(account_id, partner_id))
credits = cr.fetchall()
(rec, unrec) = do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
reconciled += rec
unreconciled += unrec
(rec, unrec) = do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
reconciled += rec
unreconciled += unrec
# add the number of transactions for partners who have only one
# unreconciled transactions to the unreconciled count
partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or ''
cr.execute(
"SELECT count(*) " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " + partner_filter,
(account_id,))
additional_unrec = cr.fetchone()[0]
return {'reconciled':reconciled, 'unreconciled':unreconciled+additional_unrec}
# add the number of transactions for partners who have only one
# unreconciled transactions to the unreconciled count
partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or ''
cr.execute(
"SELECT count(*) " \
"FROM account_move_line " \
"WHERE account_id=%d " \
"AND reconcile_id IS NULL " \
"AND state <> 'draft' " + partner_filter,
(account_id,))
additional_unrec = cr.fetchone()[0]
return {'reconciled':reconciled, 'unreconciled':unreconciled+additional_unrec}
class wiz_reconcile(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':_reconcile_form, 'fields':_reconcile_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'reconcile': {
'actions': [_reconcile],
'result': {'type':'form', 'arch':_result_form, 'fields':_result_fields, 'state':[('end','OK')]}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':_reconcile_form, 'fields':_reconcile_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'reconcile': {
'actions': [_reconcile],
'result': {'type':'form', 'arch':_result_form, 'fields':_result_fields, 'state':[('end','OK')]}
}
}
wiz_reconcile('account.automatic.reconcile')

View File

@ -32,40 +32,40 @@ from tools.translate import _
_journal_form = '''<?xml version="1.0"?>
<form string="%s">
<field name="journal_id"/>
<field name="journal_id"/>
</form>''' % ('Bank reconciliation',)
_journal_fields = {
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
}
def _action_open_window(self, cr, uid, data, context):
form = data['form']
cr.execute('select default_credit_account_id from account_journal where id=%d', (form['journal_id'],))
account_id = cr.fetchone()[0]
if not account_id:
raise Exception, _('You have to define the bank account\nin the journal definition for reconciliation.')
return {
'domain': "[('journal_id','=',%d), ('account_id','=',%d), ('state','<>','draft')]" % (form['journal_id'],account_id),
'name': 'Saisie Standard',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move.line',
'view_id': False,
'context': "{'journal_id':%d}" % (form['journal_id'],),
'type': 'ir.actions.act_window'
}
form = data['form']
cr.execute('select default_credit_account_id from account_journal where id=%d', (form['journal_id'],))
account_id = cr.fetchone()[0]
if not account_id:
raise Exception, _('You have to define the bank account\nin the journal definition for reconciliation.')
return {
'domain': "[('journal_id','=',%d), ('account_id','=',%d), ('state','<>','draft')]" % (form['journal_id'],account_id),
'name': 'Saisie Standard',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move.line',
'view_id': False,
'context': "{'journal_id':%d}" % (form['journal_id'],),
'type': 'ir.actions.act_window'
}
class wiz_journal(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for bank reconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for bank reconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
wiz_journal('account.move.bank.reconcile')

View File

@ -32,26 +32,26 @@ import wizard
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="date1"/>
<field name="date2"/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.budget', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.budget', 'state':'end'}
}
}
wizard_report('account.budget.report')

View File

@ -32,31 +32,31 @@ import netsvc
_spread_form = '''<?xml version="1.0"?>
<form string="Spread">
<field name="fiscalyear"/>
<field name="amount"/>
<field name="fiscalyear"/>
<field name="amount"/>
</form>'''
_spread_fields = {
'fiscalyear': {'string':'Fiscal Year', 'type':'many2one', 'relation':'account.fiscalyear', 'required':True},
'amount': {'string':'Amount', 'type':'float', 'digits':(16,2)},
'fiscalyear': {'string':'Fiscal Year', 'type':'many2one', 'relation':'account.fiscalyear', 'required':True},
'amount': {'string':'Amount', 'type':'float', 'digits':(16,2)},
}
class wizard_budget_spread(wizard.interface):
def _spread(self, cr, uid, data, context):
service = netsvc.LocalService("object_proxy")
form = data['form']
res = service.execute(cr.dbname, uid, 'account.budget.post', 'spread', data['ids'], form['fiscalyear'], form['amount'])
return {}
def _spread(self, cr, uid, data, context):
service = netsvc.LocalService("object_proxy")
form = data['form']
res = service.execute(cr.dbname, uid, 'account.budget.post', 'spread', data['ids'], form['fiscalyear'], form['amount'])
return {}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':_spread_form, 'fields':_spread_fields, 'state':[('end','Cancel'),('spread','Spread')]}
},
'spread': {
'actions': [_spread],
'result': {'type':'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':_spread_form, 'fields':_spread_fields, 'state':[('end','Cancel'),('spread','Spread')]}
},
'spread': {
'actions': [_spread],
'result': {'type':'state', 'state':'end'}
}
}
wizard_budget_spread('account.budget.spread')

View File

@ -34,142 +34,142 @@ from tools.translate import _
_transaction_form = '''<?xml version="1.0"?>
<form string="Close Fiscal Year">
<field name="fy_id"/>
<field name="fy2_id"/>
<field name="report_new"/>
<field name="report_name" colspan="3"/>
<field name="fy_id"/>
<field name="fy2_id"/>
<field name="report_new"/>
<field name="report_name" colspan="3"/>
<separator string="Are you sure ?" colspan="4"/>
<field name="sure"/>
<separator string="Are you sure ?" colspan="4"/>
<field name="sure"/>
</form>'''
_transaction_fields = {
'fy_id': {'string':'Fiscal Year to close', 'type':'many2one', 'relation': 'account.fiscalyear','required':True, 'domain':[('state','=','draft')]},
'fy2_id': {'string':'New Fiscal Year', 'type':'many2one', 'relation': 'account.fiscalyear', 'domain':[('state','=','draft')], 'required':True},
'report_new': {'string':'Create new entries', 'type':'boolean', 'required':True, 'default': lambda *a:True},
'report_name': {'string':'Name of new entries', 'type':'char', 'size': 64, 'required':True},
'sure': {'string':'Check this box', 'type':'boolean'},
'fy_id': {'string':'Fiscal Year to close', 'type':'many2one', 'relation': 'account.fiscalyear','required':True, 'domain':[('state','=','draft')]},
'fy2_id': {'string':'New Fiscal Year', 'type':'many2one', 'relation': 'account.fiscalyear', 'domain':[('state','=','draft')], 'required':True},
'report_new': {'string':'Create new entries', 'type':'boolean', 'required':True, 'default': lambda *a:True},
'report_name': {'string':'Name of new entries', 'type':'char', 'size': 64, 'required':True},
'sure': {'string':'Check this box', 'type':'boolean'},
}
def _data_load(self, cr, uid, data, context):
data['form']['report_new'] = True
data['form']['report_name'] = 'End of Fiscal Year Entry'
return data['form']
data['form']['report_new'] = True
data['form']['report_name'] = 'End of Fiscal Year Entry'
return data['form']
def _data_save(self, cr, uid, data, context):
if not data['form']['sure']:
raise wizard.except_wizard(_('UserError'), _('Closing of fiscal year canceled, please check the box !'))
pool = pooler.get_pool(cr.dbname)
if not data['form']['sure']:
raise wizard.except_wizard(_('UserError'), _('Closing of fiscal year canceled, please check the box !'))
pool = pooler.get_pool(cr.dbname)
fy_id = data['form']['fy_id']
if data['form']['report_new']:
period = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id']).period_ids[0]
new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id'])
start_jp = new_fyear.start_journal_period_id
if not start_jp:
raise wizard.except_wizard(_('UserError'),
_('The new fiscal year should have a journal for new entries define on it'))
fy_id = data['form']['fy_id']
if data['form']['report_new']:
period = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id']).period_ids[0]
new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id'])
start_jp = new_fyear.start_journal_period_id
if not start_jp:
raise wizard.except_wizard(_('UserError'),
_('The new fiscal year should have a journal for new entries define on it'))
new_journal = start_jp.journal_id
new_journal = start_jp.journal_id
if not new_journal.default_credit_account_id or not new_journal.default_debit_account_id:
raise wizard.except_wizard(_('UserError'),
_('The journal must have default credit and debit account'))
if not new_journal.centralisation:
raise wizard.except_wizard(_('UserError'),
_('The journal must have centralised counterpart'))
if not new_journal.default_credit_account_id or not new_journal.default_debit_account_id:
raise wizard.except_wizard(_('UserError'),
_('The journal must have default credit and debit account'))
if not new_journal.centralisation:
raise wizard.except_wizard(_('UserError'),
_('The journal must have centralised counterpart'))
query_line = pool.get('account.move.line')._query_get(cr, uid,
obj='account_move_line', context={'fiscalyear': fy_id})
cr.execute('select id from account_account WHERE active')
ids = map(lambda x: x[0], cr.fetchall())
for account in pool.get('account.account').browse(cr, uid, ids,
context={'fiscalyear': fy_id}):
if account.close_method=='none' or account.type == 'view':
continue
if account.close_method=='balance':
if abs(account.balance)>0.0001:
pool.get('account.move.line').create(cr, uid, {
'debit': account.balance>0 and account.balance,
'credit': account.balance<0 and -account.balance,
'name': data['form']['report_name'],
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
'account_id': account.id
}, {'journal_id': new_journal.id, 'period_id':period.id})
if account.close_method=='unreconciled':
offset = 0
limit = 100
while True:
cr.execute('SELECT name, quantity, debit, credit, account_id, ref, ' \
'amount_currency, currency_id, blocked, partner_id, ' \
'date_maturity, date_created ' \
'FROM account_move_line ' \
'WHERE account_id = %d ' \
'AND ' + query_line + ' ' \
'AND reconcile_id is NULL ' \
'ORDER BY id ' \
'LIMIT %d OFFSET %d', (account.id, limit, offset))
result = cr.dictfetchall()
if not result:
break
for move in result:
move.update({
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
})
pool.get('account.move.line').create(cr, uid, move, {
'journal_id': new_journal.id,
'period_id': period.id,
})
offset += limit
if account.close_method=='detail':
offset = 0
limit = 100
while True:
cr.execute('SELECT name, quantity, debit, credit, account_id, ref, ' \
'amount_currency, currency_id, blocked, partner_id, ' \
'date_maturity, date_created ' \
'FROM account_move_line ' \
'WHERE account_id = %d ' \
'AND ' + query_line + ' ' \
'ORDER BY id ' \
'LIMIT %d OFFSET %d', (account.id,fy_id, limit, offset))
result = cr.dictfetchall()
if not result:
break
for move in result:
move.update({
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
})
pool.get('account.move.line').create(cr, uid, move)
offset += limit
query_line = pool.get('account.move.line')._query_get(cr, uid,
obj='account_move_line', context={'fiscalyear': fy_id})
cr.execute('select id from account_account WHERE active')
ids = map(lambda x: x[0], cr.fetchall())
for account in pool.get('account.account').browse(cr, uid, ids,
context={'fiscalyear': fy_id}):
if account.close_method=='none' or account.type == 'view':
continue
if account.close_method=='balance':
if abs(account.balance)>0.0001:
pool.get('account.move.line').create(cr, uid, {
'debit': account.balance>0 and account.balance,
'credit': account.balance<0 and -account.balance,
'name': data['form']['report_name'],
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
'account_id': account.id
}, {'journal_id': new_journal.id, 'period_id':period.id})
if account.close_method=='unreconciled':
offset = 0
limit = 100
while True:
cr.execute('SELECT name, quantity, debit, credit, account_id, ref, ' \
'amount_currency, currency_id, blocked, partner_id, ' \
'date_maturity, date_created ' \
'FROM account_move_line ' \
'WHERE account_id = %d ' \
'AND ' + query_line + ' ' \
'AND reconcile_id is NULL ' \
'ORDER BY id ' \
'LIMIT %d OFFSET %d', (account.id, limit, offset))
result = cr.dictfetchall()
if not result:
break
for move in result:
move.update({
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
})
pool.get('account.move.line').create(cr, uid, move, {
'journal_id': new_journal.id,
'period_id': period.id,
})
offset += limit
if account.close_method=='detail':
offset = 0
limit = 100
while True:
cr.execute('SELECT name, quantity, debit, credit, account_id, ref, ' \
'amount_currency, currency_id, blocked, partner_id, ' \
'date_maturity, date_created ' \
'FROM account_move_line ' \
'WHERE account_id = %d ' \
'AND ' + query_line + ' ' \
'ORDER BY id ' \
'LIMIT %d OFFSET %d', (account.id,fy_id, limit, offset))
result = cr.dictfetchall()
if not result:
break
for move in result:
move.update({
'date': period.date_start,
'journal_id': new_journal.id,
'period_id': period.id,
})
pool.get('account.move.line').create(cr, uid, move)
offset += limit
cr.execute('UPDATE account_journal_period ' \
'SET state = %s ' \
'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %d)',
('done',fy_id))
cr.execute('UPDATE account_period SET state = %s ' \
'WHERE fiscalyear_id = %d', ('done',fy_id))
cr.execute('UPDATE account_fiscalyear ' \
'SET state = %s, end_journal_period_id = %d' \
'WHERE id = %d', ('done',start_jp,fy_id))
return {}
cr.execute('UPDATE account_journal_period ' \
'SET state = %s ' \
'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %d)',
('done',fy_id))
cr.execute('UPDATE account_period SET state = %s ' \
'WHERE fiscalyear_id = %d', ('done',fy_id))
cr.execute('UPDATE account_fiscalyear ' \
'SET state = %s, end_journal_period_id = %d' \
'WHERE id = %d', ('done',start_jp,fy_id))
return {}
class wiz_journal_close(wizard.interface):
states = {
'init': {
'actions': [_data_load],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close Fiscal Year')]}
},
'close': {
'actions': [_data_save],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [_data_load],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close Fiscal Year')]}
},
'close': {
'actions': [_data_save],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_journal_close('account.fiscalyear.close')

View File

@ -32,31 +32,31 @@ import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="fiscalyear" colspan="4"/>
<field name="periods" colspan="4"/>
<field name="fiscalyear" colspan="4"/>
<field name="periods" colspan="4"/>
</form>'''
dates_fields = {
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
return data['form']
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.general.ledger', 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.general.ledger', 'state':'end'}
}
}
wizard_report('account.general.ledger.report')

View File

@ -31,34 +31,34 @@ import wizard
import netsvc
def _invoice_confirm(self, cr, uid, data, context):
wf_service = netsvc.LocalService('workflow')
for id in data['ids']:
wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_open', cr)
return {}
wf_service = netsvc.LocalService('workflow')
for id in data['ids']:
wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_open', cr)
return {}
class wizard_invoice_confirm(wizard.interface):
states = {
'init': {
'actions': [_invoice_confirm],
'result': {'type':'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [_invoice_confirm],
'result': {'type':'state', 'state':'end'}
}
}
wizard_invoice_confirm('account.invoice.state.confirm')
def _invoice_cancel(self, cr, uid, data, context):
wf_service = netsvc.LocalService('workflow')
for id in data['ids']:
wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
return {}
wf_service = netsvc.LocalService('workflow')
for id in data['ids']:
wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
return {}
class wizard_invoice_cancel(wizard.interface):
states = {
'init': {
'actions': [_invoice_cancel],
'result': {'type':'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [_invoice_cancel],
'result': {'type':'state', 'state':'end'}
}
}
wizard_invoice_cancel('account.invoice.state.cancel')

View File

@ -34,65 +34,65 @@ from tools.translate import _
_journal_form = '''<?xml version="1.0"?>
<form string="Standard entries">
<field name="journal_id"/>
<newline/>
<field name="period_id"/>
<field name="journal_id"/>
<newline/>
<field name="period_id"/>
</form>'''
def _period_get(self, cr, uid, datas, ctx={}):
try:
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=ctx)
return {'period_id': ids[0]}
except:
return {}
try:
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=ctx)
return {'period_id': ids[0]}
except:
return {}
_journal_fields = {
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
'period_id': {
'string':'Period',
'type':'many2one',
'relation':'account.period',
'required':True,
}
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
'period_id': {
'string':'Period',
'type':'many2one',
'relation':'account.period',
'required':True,
}
}
def _action_open_window(self, cr, uid, data, context):
form = data['form']
cr.execute('select id,name from ir_ui_view where model=%s and type=%s', ('account.move.line', 'form'))
view_res = cr.fetchone()
jp = pooler.get_pool(cr.dbname).get('account.journal.period')
ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
if not len(ids):
name = pooler.get_pool(cr.dbname).get('account.journal').read(cr, uid, [form['journal_id']])[0]['name']
state = pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [form['period_id']])[0]['state']
if state == 'done':
raise wizard.except_wizard(_('UserError'), _('This period is already closed !'))
jp.create(cr, uid, {'name':name, 'period_id': form['period_id'], 'journal_id':form['journal_id']})
ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
jp = jp.browse(cr, uid, ids, context=context)[0]
name = (jp.journal_id.code or '') + ':' + (jp.period_id.code or '')
return {
'domain': "[('journal_id','=',%d), ('period_id','=',%d)]" % (form['journal_id'],form['period_id']),
'name': name,
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move.line',
'view_id': view_res,
'context': "{'journal_id':%d, 'period_id':%d}" % (form['journal_id'],form['period_id']),
'type': 'ir.actions.act_window'
}
form = data['form']
cr.execute('select id,name from ir_ui_view where model=%s and type=%s', ('account.move.line', 'form'))
view_res = cr.fetchone()
jp = pooler.get_pool(cr.dbname).get('account.journal.period')
ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
if not len(ids):
name = pooler.get_pool(cr.dbname).get('account.journal').read(cr, uid, [form['journal_id']])[0]['name']
state = pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [form['period_id']])[0]['state']
if state == 'done':
raise wizard.except_wizard(_('UserError'), _('This period is already closed !'))
jp.create(cr, uid, {'name':name, 'period_id': form['period_id'], 'journal_id':form['journal_id']})
ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
jp = jp.browse(cr, uid, ids, context=context)[0]
name = (jp.journal_id.code or '') + ':' + (jp.period_id.code or '')
return {
'domain': "[('journal_id','=',%d), ('period_id','=',%d)]" % (form['journal_id'],form['period_id']),
'name': name,
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move.line',
'view_id': view_res,
'context': "{'journal_id':%d, 'period_id':%d}" % (form['journal_id'],form['period_id']),
'type': 'ir.actions.act_window'
}
class wiz_journal(wizard.interface):
states = {
'init': {
'actions': [_period_get],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open Journal')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [_period_get],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open Journal')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
wiz_journal('account.move.journal')

View File

@ -31,26 +31,26 @@ import wizard
import pooler
def _action_open_window(self, cr, uid, data, context):
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_select')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_select')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
cr.execute('select journal_id,period_id from account_journal_period where id=%d', (data['id'],))
journal_id,period_id = cr.fetchone()
cr.execute('select journal_id,period_id from account_journal_period where id=%d', (data['id'],))
journal_id,period_id = cr.fetchone()
result['domain'] = str([('journal_id', '=', journal_id), ('period_id', '=', period_id)])
result['context'] = str({'journal_id': journal_id, 'period_id': period_id})
return result
result['domain'] = str([('journal_id', '=', journal_id), ('period_id', '=', period_id)])
result['context'] = str({'journal_id': journal_id, 'period_id': period_id})
return result
class wiz_journal(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
wiz_journal('account.move.journal.select')

View File

@ -31,35 +31,35 @@ import wizard
import pooler
class wizard_move_line_select(wizard.interface):
def _open_window(self, cr, uid, data, context):
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
def _open_window(self, cr, uid, data, context):
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
if not context.get('fiscalyear', False):
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
else:
fiscalyear_ids = [context['fiscalyear']]
if not context.get('fiscalyear', False):
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
else:
fiscalyear_ids = [context['fiscalyear']]
fiscalyears = fiscalyear_obj.browse(cr, uid, fiscalyear_ids)
period_ids = []
for fiscalyear in fiscalyears:
for period in fiscalyear.period_ids:
period_ids.append(period.id)
domain = str(('period_id', 'in', period_ids))
fiscalyears = fiscalyear_obj.browse(cr, uid, fiscalyear_ids)
period_ids = []
for fiscalyear in fiscalyears:
for period in fiscalyear.period_ids:
period_ids.append(period.id)
domain = str(('period_id', 'in', period_ids))
result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_tree1')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
result['context'] = str({'fiscalyear': context.get('fiscalyear', False)})
result['domain']=result['domain'][0:-1]+','+domain+result['domain'][-1]
return result
result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_tree1')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
result['context'] = str({'fiscalyear': context.get('fiscalyear', False)})
result['domain']=result['domain'][0:-1]+','+domain+result['domain'][-1]
return result
states = {
'init': {
'actions': [],
'result': {'type': 'action', 'action': _open_window, 'state': 'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'action', 'action': _open_window, 'state': 'end'}
}
}
wizard_move_line_select('account.move.line.select')

View File

@ -33,53 +33,53 @@ from tools.translate import _
form = """<?xml version="1.0"?>
<form string="Choose Fiscal Year">
<field name="fyear_id" domain="[('state','=','done')]"/>
<field name="fyear_id" domain="[('state','=','done')]"/>
</form>
"""
fields = {
'fyear_id': {'string': 'Fiscal Year to Open', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
'fyear_id': {'string': 'Fiscal Year to Open', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
}
def _remove_entries(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
data_fyear = pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear_id'])
if not data_fyear.end_journal_period_id:
raise wizard.except_wizard(_('Error'), _('No journal for ending writings have been defined for the fiscal year'))
period_journal = data_fyear.end_journal_period_id
if not period_journal.journal_id.centralisation:
raise wizard.except_wizard(_('UserError'), _('The journal must have centralised counterpart'))
ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
pool.get('account.move').unlink(cr,uid,ids_move)
cr.execute('UPDATE account_journal_period ' \
'SET state = %s ' \
'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %d)',
('draft',data_fyear))
cr.execute('UPDATE account_period SET state = %s ' \
'WHERE fiscalyear_id = %d', ('draft',data_fyear))
cr.execute('UPDATE account_fiscalyear ' \
'SET state = %s, end_journal_period_id = null '\
'WHERE id = %d', ('draft',data_fyear))
return {}
pool = pooler.get_pool(cr.dbname)
data_fyear = pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear_id'])
if not data_fyear.end_journal_period_id:
raise wizard.except_wizard(_('Error'), _('No journal for ending writings have been defined for the fiscal year'))
period_journal = data_fyear.end_journal_period_id
if not period_journal.journal_id.centralisation:
raise wizard.except_wizard(_('UserError'), _('The journal must have centralised counterpart'))
ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
pool.get('account.move').unlink(cr,uid,ids_move)
cr.execute('UPDATE account_journal_period ' \
'SET state = %s ' \
'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %d)',
('draft',data_fyear))
cr.execute('UPDATE account_period SET state = %s ' \
'WHERE fiscalyear_id = %d', ('draft',data_fyear))
cr.execute('UPDATE account_fiscalyear ' \
'SET state = %s, end_journal_period_id = null '\
'WHERE id = %d', ('draft',data_fyear))
return {}
class open_closed_fiscal(wizard.interface):
states = {
'init' : {
'actions' : [],
'result': {
'type': 'form',
'arch': form,
'fields': fields,
'state':[('end','Cancel'),('open','Open')]
}
},
'open': {
'actions': [],
'result': {
'type':'action',
'action':_remove_entries,
'state':'end'
},
},
}
states = {
'init' : {
'actions' : [],
'result': {
'type': 'form',
'arch': form,
'fields': fields,
'state':[('end','Cancel'),('open','Open')]
}
},
'open': {
'actions': [],
'result': {
'type':'action',
'action':_remove_entries,
'state':'end'
},
},
}
open_closed_fiscal("account.open_closed_fiscalyear")

View File

@ -33,45 +33,45 @@ import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="company_id" colspan="4"/>
<newline/>
<field name="fiscalyear" colspan="4"/>
<newline/>
<field name="date1"/>
<field name="date2"/>
<field name="company_id" colspan="4"/>
<newline/>
<field name="fiscalyear" colspan="4"/>
<newline/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.partner.balance', 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.partner.balance', 'state':'end'}
}
}
wizard_report('account.partner.balance.report')

View File

@ -35,105 +35,105 @@ from tools.translate import _
pay_form = '''<?xml version="1.0"?>
<form string="Pay invoice">
<field name="amount"/>
<newline/>
<field name="name"/>
<field name="date"/>
<field name="journal_id"/>
<field name="period_id"/>
<field name="amount"/>
<newline/>
<field name="name"/>
<field name="date"/>
<field name="journal_id"/>
<field name="period_id"/>
</form>'''
pay_fields = {
'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
'journal_id': {'string': 'Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
'journal_id': {'string': 'Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
}
def _pay_and_reconcile(self, cr, uid, data, context):
form = data['form']
period_id = form.get('period_id', False)
journal_id = form.get('journal_id', False)
writeoff_account_id = form.get('writeoff_acc_id', False)
writeoff_journal_id = form.get('writeoff_journal_id', False)
pool = pooler.get_pool(cr.dbname)
cur_obj = pool.get('res.currency')
amount = form['amount']
form = data['form']
period_id = form.get('period_id', False)
journal_id = form.get('journal_id', False)
writeoff_account_id = form.get('writeoff_acc_id', False)
writeoff_journal_id = form.get('writeoff_journal_id', False)
pool = pooler.get_pool(cr.dbname)
cur_obj = pool.get('res.currency')
amount = form['amount']
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
ctx = {'date':data['form']['date']}
amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
ctx = {'date':data['form']['date']}
amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
if not acc_id:
raise wizard.except_wizard(_('Error !'), _('Your journal must have a default credit and debit account.'))
pool.get('account.invoice').pay_and_reconcile(cr, uid, [data['id']],
amount, acc_id, period_id, journal_id, writeoff_account_id,
period_id, writeoff_journal_id, context, data['form']['name'])
return {}
acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
if not acc_id:
raise wizard.except_wizard(_('Error !'), _('Your journal must have a default credit and debit account.'))
pool.get('account.invoice').pay_and_reconcile(cr, uid, [data['id']],
amount, acc_id, period_id, journal_id, writeoff_account_id,
period_id, writeoff_journal_id, context, data['form']['name'])
return {}
def _wo_check(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
if invoice.company_id.currency_id.id<>journal.currency.id:
return 'addendum'
if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
(data['form']['amount'] - invoice.amount_total)):
return 'reconcile'
return 'addendum'
pool = pooler.get_pool(cr.dbname)
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
if invoice.company_id.currency_id.id<>journal.currency.id:
return 'addendum'
if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
(data['form']['amount'] - invoice.amount_total)):
return 'reconcile'
return 'addendum'
_transaction_add_form = '''<?xml version="1.0"?>
<form string="Information addendum">
<separator string="Write-Off Move" colspan="4"/>
<field name="writeoff_acc_id"/>
<field name="writeoff_journal_id"/>
<separator string="Write-Off Move" colspan="4"/>
<field name="writeoff_acc_id"/>
<field name="writeoff_journal_id"/>
</form>'''
_transaction_add_fields = {
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
}
def _get_value_addendum(self, cr, uid, data, context={}):
return {}
return {}
def _get_period(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=context)
period_id = False
if len(ids):
period_id = ids[0]
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
if invoice.state == 'draft':
raise wizard.except_wizard(_('Error !'), _('Can not pay draft invoice.'))
return {
'period_id': period_id,
'amount': invoice.amount_total,
'date': time.strftime('%Y-%m-%d')
}
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=context)
period_id = False
if len(ids):
period_id = ids[0]
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
if invoice.state == 'draft':
raise wizard.except_wizard(_('Error !'), _('Can not pay draft invoice.'))
return {
'period_id': period_id,
'amount': invoice.amount_total,
'date': time.strftime('%Y-%m-%d')
}
class wizard_pay_invoice(wizard.interface):
states = {
'init': {
'actions': [_get_period],
'result': {'type':'form', 'arch':pay_form, 'fields':pay_fields, 'state':[('end','Cancel'),('reconcile','Partial Payment'),('writeoff_check','Full Payment')]}
},
'writeoff_check': {
'actions': [],
'result' : {'type': 'choice', 'next_state': _wo_check }
},
'addendum': {
'actions': [_get_value_addendum],
'result': {'type': 'form', 'arch':_transaction_add_form, 'fields':_transaction_add_fields, 'state':[('end','Cancel'),('reconcile','Pay and reconcile')]}
},
'reconcile': {
'actions': [_pay_and_reconcile],
'result': {'type':'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_period],
'result': {'type':'form', 'arch':pay_form, 'fields':pay_fields, 'state':[('end','Cancel'),('reconcile','Partial Payment'),('writeoff_check','Full Payment')]}
},
'writeoff_check': {
'actions': [],
'result' : {'type': 'choice', 'next_state': _wo_check }
},
'addendum': {
'actions': [_get_value_addendum],
'result': {'type': 'form', 'arch':_transaction_add_form, 'fields':_transaction_add_fields, 'state':[('end','Cancel'),('reconcile','Pay and reconcile')]}
},
'reconcile': {
'actions': [_pay_and_reconcile],
'result': {'type':'state', 'state':'end'}
}
}
wizard_pay_invoice('account.invoice.pay')

View File

@ -31,32 +31,32 @@ import wizard
_transaction_form = '''<?xml version="1.0"?>
<form string="Close Period">
<separator string="Are you sure ?" colspan="4"/>
<field name="sure"/>
<separator string="Are you sure ?" colspan="4"/>
<field name="sure"/>
</form>'''
_transaction_fields = {
'sure': {'string':'Check this box', 'type':'boolean'},
'sure': {'string':'Check this box', 'type':'boolean'},
}
def _data_save(self, cr, uid, data, context):
mode = 'done'
if data['form']['sure']:
for id in data['ids']:
cr.execute('update account_journal_period set state=%s where period_id=%d', (mode, id))
cr.execute('update account_period set state=%s where id=%d', (mode, id))
return {}
mode = 'done'
if data['form']['sure']:
for id in data['ids']:
cr.execute('update account_journal_period set state=%s where period_id=%d', (mode, id))
cr.execute('update account_period set state=%s where id=%d', (mode, id))
return {}
class wiz_journal_close(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close Period')]}
},
'close': {
'actions': [_data_save],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close Period')]}
},
'close': {
'actions': [_data_save],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_journal_close('account.period.close')

View File

@ -35,108 +35,108 @@ import pooler
_transaction_form = '''<?xml version="1.0"?>
<form string="Reconciliation">
<separator string="Reconciliation transactions" colspan="4"/>
<field name="trans_nbr"/>
<newline/>
<field name="credit"/>
<field name="debit"/>
<separator string="Write-Off" colspan="4"/>
<field name="writeoff"/>
<separator string="Reconciliation transactions" colspan="4"/>
<field name="trans_nbr"/>
<newline/>
<field name="credit"/>
<field name="debit"/>
<separator string="Write-Off" colspan="4"/>
<field name="writeoff"/>
</form>'''
_transaction_fields = {
'trans_nbr': {'string':'# of Transaction', 'type':'integer', 'readonly':True},
'credit': {'string':'Credit amount', 'type':'float', 'readonly':True},
'debit': {'string':'Debit amount', 'type':'float', 'readonly':True},
'writeoff': {'string':'Write-Off amount', 'type':'float', 'readonly':True},
'trans_nbr': {'string':'# of Transaction', 'type':'integer', 'readonly':True},
'credit': {'string':'Credit amount', 'type':'float', 'readonly':True},
'debit': {'string':'Debit amount', 'type':'float', 'readonly':True},
'writeoff': {'string':'Write-Off amount', 'type':'float', 'readonly':True},
}
def _trans_rec_get(self, cr, uid, data, context=None):
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
credit = debit = 0
account_id = False
count = 0
for line in account_move_line_obj.browse(cr, uid, data['ids'], context=context):
if not line.reconcile_id and not line.reconcile_id.id:
count += 1
credit += line.credit
debit += line.debit
account_id = line.account_id.id
return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit}
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
credit = debit = 0
account_id = False
count = 0
for line in account_move_line_obj.browse(cr, uid, data['ids'], context=context):
if not line.reconcile_id and not line.reconcile_id.id:
count += 1
credit += line.credit
debit += line.debit
account_id = line.account_id.id
return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit}
def _trans_rec_reconcile_partial(self, cr, uid, data, context=None):
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
account_move_line_obj.reconcile_partial(cr, uid, data['ids'], 'manual', context=context)
return {}
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
account_move_line_obj.reconcile_partial(cr, uid, data['ids'], 'manual', context=context)
return {}
def _trans_rec_reconcile(self, cr, uid, data, context=None):
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
pool = pooler.get_pool(cr.dbname)
account_move_line_obj = pool.get('account.move.line')
form = data['form']
account_id = form.get('writeoff_acc_id', False)
period_id = form.get('period_id', False)
journal_id = form.get('journal_id', False)
account_move_line_obj.reconcile(cr, uid, data['ids'], 'manual', account_id,
period_id, journal_id, context=context)
return {}
form = data['form']
account_id = form.get('writeoff_acc_id', False)
period_id = form.get('period_id', False)
journal_id = form.get('journal_id', False)
account_move_line_obj.reconcile(cr, uid, data['ids'], 'manual', account_id,
period_id, journal_id, context=context)
return {}
def _partial_check(self, cr, uid, data, context):
if _trans_rec_get(self,cr,uid, data, context)['writeoff'] == 0:
return 'init_full'
return 'init_partial'
if _trans_rec_get(self,cr,uid, data, context)['writeoff'] == 0:
return 'init_full'
return 'init_partial'
_transaction_add_form = '''<?xml version="1.0"?>
<form string="Information addendum">
<separator string="Write-Off Move" colspan="4"/>
<field name="journal_id"/>
<field name="period_id"/>
<field name="writeoff_acc_id" domain="[('type', '&lt;&gt;', 'view')]"/>
<separator string="Write-Off Move" colspan="4"/>
<field name="journal_id"/>
<field name="period_id"/>
<field name="writeoff_acc_id" domain="[('type', '&lt;&gt;', 'view')]"/>
</form>'''
_transaction_add_fields = {
'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
'period_id': {'string': 'Write-Off Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
'period_id': {'string': 'Write-Off Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
}
def _trans_rec_addendum(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=context)
period_id = False
if len(ids):
period_id = ids[0]
return {'period_id':period_id}
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=context)
period_id = False
if len(ids):
period_id = ids[0]
return {'period_id':period_id}
class wiz_reconcile(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'choice', 'next_state': _partial_check}
},
'init_full': {
'actions': [_trans_rec_get],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'init_partial': {
'actions': [_trans_rec_get],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('addendum','Reconcile With Write-Off'),('partial','Partial Reconcile')]}
},
'addendum': {
'actions': [_trans_rec_addendum],
'result': {'type': 'form', 'arch':_transaction_add_form, 'fields':_transaction_add_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'reconcile': {
'actions': [_trans_rec_reconcile],
'result': {'type': 'state', 'state':'end'}
},
'partial': {
'actions': [_trans_rec_reconcile_partial],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'choice', 'next_state': _partial_check}
},
'init_full': {
'actions': [_trans_rec_get],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'init_partial': {
'actions': [_trans_rec_get],
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('addendum','Reconcile With Write-Off'),('partial','Partial Reconcile')]}
},
'addendum': {
'actions': [_trans_rec_addendum],
'result': {'type': 'form', 'arch':_transaction_add_form, 'fields':_transaction_add_fields, 'state':[('end','Cancel'),('reconcile','Reconcile')]}
},
'reconcile': {
'actions': [_trans_rec_reconcile],
'result': {'type': 'state', 'state':'end'}
},
'partial': {
'actions': [_trans_rec_reconcile_partial],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_reconcile('account.move.line.reconcile')

View File

@ -31,34 +31,34 @@ import wizard
_journal_form = '''<?xml version="1.0"?>
<form string="%s">
<field name="account_id"/>
<field name="account_id"/>
</form>''' % ('Reconciliation',)
_journal_fields = {
'account_id': {'string':'Account', 'type':'many2one', 'relation':'account.account','domain': [('reconcile','=',1)], 'required':True},
'account_id': {'string':'Account', 'type':'many2one', 'relation':'account.account','domain': [('reconcile','=',1)], 'required':True},
}
def _action_open_window(self, cr, uid, data, context):
return {
'domain': "[('account_id','=',%d),('reconcile_id','=',False),('state','<>','draft')]" % data['form']['account_id'],
'name': 'Reconciliation',
'view_type': 'form',
'view_mode': 'tree,form',
'view_id': False,
'res_model': 'account.move.line',
'type': 'ir.actions.act_window'
}
return {
'domain': "[('account_id','=',%d),('reconcile_id','=',False),('state','<>','draft')]" % data['form']['account_id'],
'name': 'Reconciliation',
'view_type': 'form',
'view_mode': 'tree,form',
'view_id': False,
'res_model': 'account.move.line',
'type': 'ir.actions.act_window'
}
class wiz_rec_select(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for reconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for reconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
wiz_rec_select('account.move.line.reconcile.select')

View File

@ -32,35 +32,35 @@ import pooler
sur_form = '''<?xml version="1.0"?>
<form string="Refund Invoice">
<label string="Are you sure you want to refund this invoice ?"/>
<label string="Are you sure you want to refund this invoice ?"/>
</form>'''
sur_fields = {
}
class wiz_refund(wizard.interface):
def _invoice_refund(self, cr, uid, data, context):
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'
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':sur_form, 'fields':sur_fields, 'state':[('end','Cancel'),('refund','Refund Invoice')]}
},
'refund': {
'actions': [],
'result': {'type':'action', 'action':_invoice_refund, 'state':'end'}
}
}
def _invoice_refund(self, cr, uid, data, context):
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'
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':sur_form, 'fields':sur_fields, 'state':[('end','Cancel'),('refund','Refund Invoice')]}
},
'refund': {
'actions': [],
'result': {'type':'action', 'action':_invoice_refund, 'state':'end'}
}
}
wiz_refund('account.invoice.refund')

View File

@ -37,30 +37,30 @@ import pooler
_subscription_form = '''<?xml version="1.0"?>
<form string="%s">
<seperator string="Generate entries before:" colspan="4"/>
<field name="date"/>
<seperator string="Generate entries before:" colspan="4"/>
<field name="date"/>
</form>''' % ('Subscription Compute',)
_subscription_fields = {
'date': {'string':'Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
'date': {'string':'Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
}
class wiz_subscription(wizard.interface):
def _action_generate(self, cr, uid, data, context):
cr.execute('select id from account_subscription_line where date<%s and move_id is null', (data['form']['date'],))
ids = map(lambda x: x[0], cr.fetchall())
pooler.get_pool(cr.dbname).get('account.subscription.line').move_create(cr, uid, ids)
return {}
def _action_generate(self, cr, uid, data, context):
cr.execute('select id from account_subscription_line where date<%s and move_id is null', (data['form']['date'],))
ids = map(lambda x: x[0], cr.fetchall())
pooler.get_pool(cr.dbname).get('account.subscription.line').move_create(cr, uid, ids)
return {}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_subscription_form, 'fields':_subscription_fields, 'state':[('end','Cancel'),('generate','Compute Entry Dates')]}
},
'generate': {
'actions': [_action_generate],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_subscription_form, 'fields':_subscription_fields, 'state':[('end','Cancel'),('generate','Compute Entry Dates')]}
},
'generate': {
'actions': [_action_generate],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_subscription('account.subscription.generate')

View File

@ -33,45 +33,45 @@ import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="company_id" colspan="4"/>
<field name="fiscalyear" colspan="4"/>
<newline/>
<field name="date1"/>
<field name="date2"/>
<field name="company_id" colspan="4"/>
<field name="fiscalyear" colspan="4"/>
<newline/>
<field name="date1"/>
<field name="date2"/>
</form>'''
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.third_party_ledger', 'state':'end'}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.third_party_ledger', 'state':'end'}
}
}
wizard_report('account.third_party_ledger.report')

View File

@ -32,49 +32,49 @@ import pooler
_info_form = '''<?xml version="1.0"?>
<form string="Unreconciliation">
<separator string="Unreconciliation transactions" colspan="4"/>
<image name="gtk-dialog-info" colspan="2"/>
<label string="If you unreconciliate transactions, you must also verify all the actions that are linked to those transactions because they will not be disable" colspan="2"/>
<separator string="Unreconciliation transactions" colspan="4"/>
<image name="gtk-dialog-info" colspan="2"/>
<label string="If you unreconciliate transactions, you must also verify all the actions that are linked to those transactions because they will not be disable" colspan="2"/>
</form>'''
def _trans_unrec(self, cr, uid, data, context):
recs = pooler.get_pool(cr.dbname).get('account.move.line').read(cr, uid, data['ids'], ['reconcile_id',])
recs = filter(lambda x: x['reconcile_id'], recs)
rec_ids = [rec['reconcile_id'][0] for rec in recs]
if len(rec_ids):
pooler.get_pool(cr.dbname).get('account.move.reconcile').unlink(cr, uid, rec_ids)
return {}
recs = pooler.get_pool(cr.dbname).get('account.move.line').read(cr, uid, data['ids'], ['reconcile_id',])
recs = filter(lambda x: x['reconcile_id'], recs)
rec_ids = [rec['reconcile_id'][0] for rec in recs]
if len(rec_ids):
pooler.get_pool(cr.dbname).get('account.move.reconcile').unlink(cr, uid, rec_ids)
return {}
class wiz_unreconcile(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': _info_form, 'fields': {}, 'state':[('end', 'Cancel'), ('unrec', 'Unreconcile')]}
},
'unrec': {
'actions': [_trans_unrec],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': _info_form, 'fields': {}, 'state':[('end', 'Cancel'), ('unrec', 'Unreconcile')]}
},
'unrec': {
'actions': [_trans_unrec],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_unreconcile('account.move.line.unreconcile')
def _trans_unrec_reconcile(self, cr, uid, data, context):
rec_ids = data['ids']
if len(rec_ids):
pooler.get_pool(cr.dbname).get('account.move.reconcile').unlink(cr, uid, rec_ids)
return {}
rec_ids = data['ids']
if len(rec_ids):
pooler.get_pool(cr.dbname).get('account.move.reconcile').unlink(cr, uid, rec_ids)
return {}
class wiz_unreconcile_reconcile(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': _info_form, 'fields': {}, 'state':[('end', 'Cancel'), ('unrec', 'Unreconcile')]}
},
'unrec': {
'actions': [_trans_unrec_reconcile],
'result': {'type': 'state', 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': _info_form, 'fields': {}, 'state':[('end', 'Cancel'), ('unrec', 'Unreconcile')]}
},
'unrec': {
'actions': [_trans_unrec_reconcile],
'result': {'type': 'state', 'state':'end'}
}
}
wiz_unreconcile_reconcile('account.reconcile.unreconcile')

View File

@ -31,34 +31,34 @@ import wizard
_journal_form = '''<?xml version="1.0"?>
<form string="%s">
<field name="account_id"/>
<field name="account_id"/>
</form>''' % ('Unreconciliation',)
_journal_fields = {
'account_id': {'string':'Account', 'type':'many2one', 'relation':'account.account', 'required':True},
'account_id': {'string':'Account', 'type':'many2one', 'relation':'account.account', 'required':True},
}
def _action_open_window(self, cr, uid, data, context):
return {
'domain': "[('account_id','=',%d),('reconcile_id','<>',False),('state','<>','draft')]" % data['form']['account_id'],
'name': 'Unreconciliation',
'view_type': 'form',
'view_mode': 'tree,form',
'view_id': False,
'res_model': 'account.move.line',
'type': 'ir.actions.act_window'
}
return {
'domain': "[('account_id','=',%d),('reconcile_id','<>',False),('state','<>','draft')]" % data['form']['account_id'],
'name': 'Unreconciliation',
'view_type': 'form',
'view_mode': 'tree,form',
'view_id': False,
'res_model': 'account.move.line',
'type': 'ir.actions.act_window'
}
class wiz_unrec_select(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for unreconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for unreconciliation')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
wiz_unrec_select('account.move.line.unreconcile.select')

View File

@ -34,58 +34,58 @@ from tools.translate import _
_journal_form = '''<?xml version="1.0"?>
<form string="Standard entries">
<field name="journal_id"/>
<newline/>
<field name="period_id"/>
<field name="journal_id"/>
<newline/>
<field name="period_id"/>
</form>'''
_journal_fields = {
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
'period_id': {'string':'Period', 'type':'many2one', 'relation':'account.period', 'required':True, 'domain':"[('state','<>','done')]"},
'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
'period_id': {'string':'Period', 'type':'many2one', 'relation':'account.period', 'required':True, 'domain':"[('state','<>','done')]"},
}
def _validate_move(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
move_obj = pool.get('account.move')
ids_move = move_obj.search(cr,uid,[('state','=','draft'),('journal_id','=',data['form']['journal_id']),('period_id','=',data['form']['period_id'])])
if not ids_move:
raise wizard.except_wizard(_('Warning'), _('Specified Journal does not have any account move entries in draft state for this period'))
res = move_obj.button_validate(cr, uid, ids_move, context)
return {}
pool = pooler.get_pool(cr.dbname)
move_obj = pool.get('account.move')
ids_move = move_obj.search(cr,uid,[('state','=','draft'),('journal_id','=',data['form']['journal_id']),('period_id','=',data['form']['period_id'])])
if not ids_move:
raise wizard.except_wizard(_('Warning'), _('Specified Journal does not have any account move entries in draft state for this period'))
res = move_obj.button_validate(cr, uid, ids_move, context)
return {}
class validate_account_move(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('validate','Validate')]}
},
'validate': {
'actions': [_validate_move],
'result': {'type': 'state', 'state':'end'}
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('validate','Validate')]}
},
'validate': {
'actions': [_validate_move],
'result': {'type': 'state', 'state':'end'}
},
}
validate_account_move('account.move.validate')
def _validate_move_lines(self, cr, uid, data, context={}):
move_ids = []
pool = pooler.get_pool(cr.dbname)
move_line_obj = pool.get('account.move.line')
move_obj = pool.get('account.move')
data_line = move_line_obj.browse(cr,uid,data['ids'],context)
for line in data_line:
if line.move_id.state=='draft':
move_ids.append(line.move_id.id)
move_ids = list(set(move_ids))
if not move_ids:
raise wizard.except_wizard(_('Warning'), _('Selected Move lines does not have any account move enties in draft state'))
res = move_obj.button_validate(cr, uid, move_ids, context)
return {}
move_ids = []
pool = pooler.get_pool(cr.dbname)
move_line_obj = pool.get('account.move.line')
move_obj = pool.get('account.move')
data_line = move_line_obj.browse(cr,uid,data['ids'],context)
for line in data_line:
if line.move_id.state=='draft':
move_ids.append(line.move_id.id)
move_ids = list(set(move_ids))
if not move_ids:
raise wizard.except_wizard(_('Warning'), _('Selected Move lines does not have any account move enties in draft state'))
res = move_obj.button_validate(cr, uid, move_ids, context)
return {}
class validate_account_move_lines(wizard.interface):
states = {
'init': {
'actions': [_validate_move_lines],
'result': {'type': 'state', 'state':'end'}
},
}
states = {
'init': {
'actions': [_validate_move_lines],
'result': {'type': 'state', 'state':'end'}
},
}
validate_account_move_lines('account.move_line.validate')

View File

@ -33,64 +33,64 @@ import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="company_id"/>
<newline/>
<field name="period_id"/>
<newline/>
<field name="based_on"/>
<field name="company_id"/>
<newline/>
<field name="period_id"/>
<newline/>
<field name="based_on"/>
</form>'''
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one',
'relation': 'res.company', 'required': True},
'period_id': {'string':'Period', 'type':'many2one',
'relation': 'account.period', 'required':True},
'based_on':{'string':'Base on', 'type':'selection', 'selection':[
('invoices','Invoices'),
('payments','Payments'),
], 'required':True, 'default': lambda *a: 'invoices'},
'company_id': {'string': 'Company', 'type': 'many2one',
'relation': 'res.company', 'required': True},
'period_id': {'string':'Period', 'type':'many2one',
'relation': 'account.period', 'required':True},
'based_on':{'string':'Base on', 'type':'selection', 'selection':[
('invoices','Invoices'),
('payments','Payments'),
], 'required':True, 'default': lambda *a: 'invoices'},
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
period_obj = pool.get('account.period')
data['form']['period_id'] = period_obj.find(cr, uid)[0]
def _get_defaults(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
period_obj = pool.get('account.period')
data['form']['period_id'] = period_obj.find(cr, uid)[0]
user = pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pool.get('res.company').search(cr, uid,
[('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
user = pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pool.get('res.company').search(cr, uid,
[('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {
'type': 'form',
'arch': dates_form,
'fields': dates_fields,
'state': [
('end', 'Cancel'),
('report', 'Print VAT Decl.')
]
}
},
'report': {
'actions': [],
'result': {
'type': 'print',
'report': 'account.vat.declaration',
'state':'end'
}
}
}
states = {
'init': {
'actions': [_get_defaults],
'result': {
'type': 'form',
'arch': dates_form,
'fields': dates_fields,
'state': [
('end', 'Cancel'),
('report', 'Print VAT Decl.')
]
}
},
'report': {
'actions': [],
'result': {
'type': 'print',
'report': 'account.vat.declaration',
'state':'end'
}
}
}
wizard_report('account.vat.declaration')

View File

@ -26,22 +26,22 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "report_account_analytic",
"description": """Modifiy the account analytic view to show
"name" : "report_account_analytic",
"description": """Modifiy the account analytic view to show
important data for project manager of services companies.
Add menu to show relevant information for each manager.""",
"version" : "1.0",
"author" : "Camptocamp",
"category" : "Generic Modules/Accounting",
"module": "",
"website": "http://www.camptocamp.com/",
"depends" : ["account","hr_timesheet","hr_timesheet_invoice"],
"init_xml" : [],
"update_xml" : [
"account_analytic_analysis_view.xml",
"account_analytic_analysis_menu.xml",
],
"demo_xml" : [],
"active": False,
"installable": True
"version" : "1.0",
"author" : "Camptocamp",
"category" : "Generic Modules/Accounting",
"module": "",
"website": "http://www.camptocamp.com/",
"depends" : ["account","hr_timesheet","hr_timesheet_invoice"],
"init_xml" : [],
"update_xml" : [
"account_analytic_analysis_view.xml",
"account_analytic_analysis_menu.xml",
],
"demo_xml" : [],
"active": False,
"installable": True
}

File diff suppressed because it is too large Load Diff

View File

@ -26,20 +26,20 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Charts of Accounts",
"version" : "1.1",
"depends" : ["account"],
"author" : "Tiny",
"description": """Remove minimal account chart""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [
],
"demo_xml" : [
],
"update_xml" : [
"name" : "Charts of Accounts",
"version" : "1.1",
"depends" : ["account"],
"author" : "Tiny",
"description": """Remove minimal account chart""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [
],
"demo_xml" : [
],
"update_xml" : [
# Must be loaded by each modules
# "account_chart.xml",
],
"installable": True
# "account_chart.xml",
],
"installable": True
}

View File

@ -26,32 +26,32 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Accounting follow-ups management",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """
Modules to automate letters for unpaid invoices, with multi-level recalls.
"name" : "Accounting follow-ups management",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """
Modules to automate letters for unpaid invoices, with multi-level recalls.
You can define your multiple levels of recall through the menu:
Financial Management/Configuration/Payment Terms/Follow-Ups
You can define your multiple levels of recall through the menu:
Financial Management/Configuration/Payment Terms/Follow-Ups
Once it's defined, you can automatically prints recall every days
through simply clicking on the menu:
Financial_Management/Periodical_Processing/Print_Follow-Ups
Once it's defined, you can automatically prints recall every days
through simply clicking on the menu:
Financial_Management/Periodical_Processing/Print_Follow-Ups
It will generate a PDF with all the letters according the the
different levels of recall defined. You can define different policies
for different companies.""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [],
"demo_xml" : ["followup_demo.xml"],
"update_xml" : [
"followup_view.xml",
"followup_report_view.xml"
],
"active": False,
"installable": True
It will generate a PDF with all the letters according the the
different levels of recall defined. You can define different policies
for different companies.""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [],
"demo_xml" : ["followup_demo.xml"],
"update_xml" : [
"followup_view.xml",
"followup_report_view.xml"
],
"active": False,
"installable": True
}

View File

@ -31,36 +31,36 @@
from osv import fields, osv
class followup(osv.osv):
_name = 'account_followup.followup'
_description = 'Follow-Ups'
_columns = {
'name': fields.char('Name', size=64, required=True),
'description': fields.text('Description'),
'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-Up'),
'company_id': fields.many2one('res.company', 'Company'),
}
_name = 'account_followup.followup'
_description = 'Follow-Ups'
_columns = {
'name': fields.char('Name', size=64, required=True),
'description': fields.text('Description'),
'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-Up'),
'company_id': fields.many2one('res.company', 'Company'),
}
followup()
class followup_line(osv.osv):
_name = 'account_followup.followup.line'
_description = 'Follow-Ups Criteria'
_columns = {
'name': fields.char('Name', size=64, required=True),
'sequence': fields.integer('Sequence'),
'delay': fields.integer('Days of delay'),
'start': fields.selection([('days','Net Days'),('end_of_month','End of Month')], 'Type of Term', size=64, required=True),
'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"),
'description': fields.text('Printed Message'),
#'prints': fields.one2many('account_followup.followup.print', 'line_id'),
}
_name = 'account_followup.followup.line'
_description = 'Follow-Ups Criteria'
_columns = {
'name': fields.char('Name', size=64, required=True),
'sequence': fields.integer('Sequence'),
'delay': fields.integer('Days of delay'),
'start': fields.selection([('days','Net Days'),('end_of_month','End of Month')], 'Type of Term', size=64, required=True),
'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"),
'description': fields.text('Printed Message'),
#'prints': fields.one2many('account_followup.followup.print', 'line_id'),
}
followup_line()
class account_move_line(osv.osv):
_name = 'account.move.line'
_inherit = 'account.move.line'
_columns = {
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level'),
'followup_date': fields.date('Latest Follow-up'),
}
_name = 'account.move.line'
_inherit = 'account.move.line'
_columns = {
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level'),
'followup_date': fields.date('Latest Follow-up'),
}
account_move_line()

View File

@ -31,55 +31,55 @@
from osv import fields, osv
def _code_get(self, cr, uid, context={}):
acc_type_obj = self.pool.get('account.account.type')
ids = acc_type_obj.search(cr, uid, [])
res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
return [(r['code'], r['name']) for r in res]
acc_type_obj = self.pool.get('account.account.type')
ids = acc_type_obj.search(cr, uid, [])
res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
return [(r['code'], r['name']) for r in res]
class account_followup_stat(osv.osv):
_name = "account_followup.stat"
_description = "Followup statistics"
_auto = False
_columns = {
'name': fields.many2one('res.partner', 'Partner', readonly=True),
'account_type': fields.selection(_code_get, 'Account Type', readonly=True),
'date_move':fields.date('First move', readonly=True),
'date_move_last':fields.date('Last move', readonly=True),
'date_followup':fields.date('Latest followup', readonly=True),
'followup_id': fields.many2one('account_followup.followup.line',
'Follow Ups', readonly=True, ondelete="cascade"),
'balance':fields.float('Balance', readonly=True),
'debit':fields.float('Debit', readonly=True),
'credit':fields.float('Credit', readonly=True),
}
_order = 'date_move'
def init(self, cr):
cr.execute("""
create or replace view account_followup_stat as (
select
min(l.id) as id,
l.partner_id as name,
min(l.date) as date_move,
max(l.date) as date_move_last,
max(l.followup_date) as date_followup,
max(l.followup_line_id) as followup_id,
sum(l.debit) as debit,
sum(l.credit) as credit,
sum(l.debit - l.credit) as balance,
a.type as account_type
from
account_move_line l
left join
account_account a on (l.account_id=a.id)
where
l.reconcile_id is NULL and
a.type in ('receivable', 'payable')
and a.active and
l.partner_id is not null
group by
l.partner_id, a.type
)""")
_name = "account_followup.stat"
_description = "Followup statistics"
_auto = False
_columns = {
'name': fields.many2one('res.partner', 'Partner', readonly=True),
'account_type': fields.selection(_code_get, 'Account Type', readonly=True),
'date_move':fields.date('First move', readonly=True),
'date_move_last':fields.date('Last move', readonly=True),
'date_followup':fields.date('Latest followup', readonly=True),
'followup_id': fields.many2one('account_followup.followup.line',
'Follow Ups', readonly=True, ondelete="cascade"),
'balance':fields.float('Balance', readonly=True),
'debit':fields.float('Debit', readonly=True),
'credit':fields.float('Credit', readonly=True),
}
_order = 'date_move'
def init(self, cr):
cr.execute("""
create or replace view account_followup_stat as (
select
min(l.id) as id,
l.partner_id as name,
min(l.date) as date_move,
max(l.date) as date_move_last,
max(l.followup_date) as date_followup,
max(l.followup_line_id) as followup_id,
sum(l.debit) as debit,
sum(l.credit) as credit,
sum(l.debit - l.credit) as balance,
a.type as account_type
from
account_move_line l
left join
account_account a on (l.account_id=a.id)
where
l.reconcile_id is NULL and
a.type in ('receivable', 'payable')
and a.active and
l.partner_id is not null
group by
l.partner_id, a.type
)""")
account_followup_stat()

View File

@ -34,39 +34,39 @@ from osv import osv
from report import report_sxw
class report_rappel(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(report_rappel, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time' : time,
'ids_to_objects': self._ids_to_objects,
'adr_get' : self._adr_get,
'getLines' : self._lines_get,
})
def __init__(self, cr, uid, name, context):
super(report_rappel, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time' : time,
'ids_to_objects': self._ids_to_objects,
'adr_get' : self._adr_get,
'getLines' : self._lines_get,
})
def _ids_to_objects(self, partners_ids):
pool = pooler.get_pool(self.cr.dbname)
all_partners = []
for partner in partners_ids:
partners = pool.get('account_followup.stat').browse(self.cr, self.uid, partner[2])
for par in partners:
all_partners.append(par.name)
return all_partners
def _ids_to_objects(self, partners_ids):
pool = pooler.get_pool(self.cr.dbname)
all_partners = []
for partner in partners_ids:
partners = pool.get('account_followup.stat').browse(self.cr, self.uid, partner[2])
for par in partners:
all_partners.append(par.name)
return all_partners
def _adr_get(self, partner, type):
res_partner = pooler.get_pool(self.cr.dbname).get('res.partner')
res_partner_address = pooler.get_pool(self.cr.dbname).get('res.partner.address')
adr = res_partner.address_get(self.cr, self.uid, [partner.id], [type])[type]
return res_partner_address.read(self.cr, self.uid, [adr])
def _adr_get(self, partner, type):
res_partner = pooler.get_pool(self.cr.dbname).get('res.partner')
res_partner_address = pooler.get_pool(self.cr.dbname).get('res.partner.address')
adr = res_partner.address_get(self.cr, self.uid, [partner.id], [type])[type]
return res_partner_address.read(self.cr, self.uid, [adr])
def _lines_get(self, partner):
moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
movelines = moveline_obj.search(self.cr, self.uid,
[('partner_id', '=', partner.id),
('account_id.type', '=', 'receivable'),
('reconcile_id', '=', False), ('state', '<>', 'draft')])
movelines = moveline_obj.read(self.cr, self.uid, movelines)
return movelines
def _lines_get(self, partner):
moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
movelines = moveline_obj.search(self.cr, self.uid,
[('partner_id', '=', partner.id),
('account_id.type', '=', 'receivable'),
('reconcile_id', '=', False), ('state', '<>', 'draft')])
movelines = moveline_obj.read(self.cr, self.uid, movelines)
return movelines
report_sxw.report_sxw('report.account_followup.followup.print',
'res.partner', 'addons/account_followup/report/rappel.rml',
parser=report_rappel)
'res.partner', 'addons/account_followup/report/rappel.rml',
parser=report_rappel)

View File

@ -38,73 +38,73 @@ from tools.translate import _
_followup_wizard_date_form = """<?xml version="1.0"?>
<form string="Select a date">
<field name="date"/>
<field name="date"/>
</form>"""
_followup_wizard_date_fields = {
'date': {'string': 'Date', 'type': 'date', 'required': True},
'date': {'string': 'Date', 'type': 'date', 'required': True},
}
form = """<?xml version="1.0"?>
<form string="Mail">
<field name="mail_sent" colspan="4"/>
<newline/>
<newline/>
<separator string="Mail not sent to following Partners , Email not available !" colspan="4"/>
<field name="mail_notsent" colspan="4" nolabel="1"/>
<field name="mail_sent" colspan="4"/>
<newline/>
<newline/>
<separator string="Mail not sent to following Partners , Email not available !" colspan="4"/>
<field name="mail_notsent" colspan="4" nolabel="1"/>
</form>"""
fields = {
'mail_sent': {'string':'Number of Mail sent', 'type':'char', 'readonly':True },
'mail_notsent': {'string':'Error Messages', 'type':'text', 'readonly':True , 'nolabel':'1'},
}
'mail_sent': {'string':'Number of Mail sent', 'type':'char', 'readonly':True },
'mail_notsent': {'string':'Error Messages', 'type':'text', 'readonly':True , 'nolabel':'1'},
}
_followup_wizard_all_form = """<?xml version="1.0"?>
<form string="Select partners" colspan="4">
<notebook>
<page string="FollowUp selection">
<separator string="Select partners to remind" colspan="4"/>
<field name="partner_ids" colspan="4" nolabel="1"/>
</page>
<page string="Email confirmation">
<field name="email_conf" colspan="4"/>
<field name="email_subject" colspan="4"/>
<separator string="Email body" colspan="4"/>
<field name="email_body" colspan="4" nolabel="1"/>
<separator string="Legend" colspan="4"/>
<notebook>
<page string="FollowUp selection">
<separator string="Select partners to remind" colspan="4"/>
<field name="partner_ids" colspan="4" nolabel="1"/>
</page>
<page string="Email confirmation">
<field name="email_conf" colspan="4"/>
<field name="email_subject" colspan="4"/>
<separator string="Email body" colspan="4"/>
<field name="email_body" colspan="4" nolabel="1"/>
<separator string="Legend" colspan="4"/>
<label string="%(partner_name)s: Partner name" colspan="2"/>
<label string="%(followup_amount)s: Total Amount Due" colspan="2"/>
<label string="%(user_signature)s: User name" colspan="2"/>
<label string="%(company_name)s: User's Company name" colspan="2"/>
<label string="%(line)s: Account Move lines" colspan="2"/>
<label string="%(heading)s: Move line header" colspan="2"/>
<label string="%(date)s: Current Date" colspan="2"/>
</page>
</notebook>
<label string="%(partner_name)s: Partner name" colspan="2"/>
<label string="%(followup_amount)s: Total Amount Due" colspan="2"/>
<label string="%(user_signature)s: User name" colspan="2"/>
<label string="%(company_name)s: User's Company name" colspan="2"/>
<label string="%(line)s: Account Move lines" colspan="2"/>
<label string="%(heading)s: Move line header" colspan="2"/>
<label string="%(date)s: Current Date" colspan="2"/>
</page>
</notebook>
</form>"""
_followup_wizard_all_fields = {
'partner_ids': {
'string': "Partners",
'type': 'many2many',
'relation': 'account_followup.stat',
'domain':"[('account_type','=','receivable')]"
},
'email_conf': {
'string': "Send email confirmation",
'type': 'boolean',
},
'email_subject' : {
'string' : "Email Subject",
'type' : "char",
'size': 64,
'default': 'Account Follow-up'
},
'email_body': {
'string': "Email body",
'type': 'text',
'default': '''
'partner_ids': {
'string': "Partners",
'type': 'many2many',
'relation': 'account_followup.stat',
'domain':"[('account_type','=','receivable')]"
},
'email_conf': {
'string': "Send email confirmation",
'type': 'boolean',
},
'email_subject' : {
'string' : "Email Subject",
'type' : "char",
'size': 64,
'default': 'Account Follow-up'
},
'email_body': {
'string': "Email body",
'type': 'text',
'default': '''
Date : %(date)s
Dear %(partner_name)s,
@ -126,183 +126,183 @@ Thanks,
--
%(user_signature)s
%(company_name)s
'''
}
'''
}
}
class followup_all_print(wizard.interface):
def _update_partners(self, cr, uid, data, context):
to_update = data['form']['to_update']
for id in to_update.keys():
cr.execute(
"UPDATE account_move_line "\
"SET followup_line_id=%d, followup_date=%s "\
"WHERE id=%d",
(to_update[id],
data['form']['date'], int(id),))
return {}
def _update_partners(self, cr, uid, data, context):
to_update = data['form']['to_update']
for id in to_update.keys():
cr.execute(
"UPDATE account_move_line "\
"SET followup_line_id=%d, followup_date=%s "\
"WHERE id=%d",
(to_update[id],
data['form']['date'], int(id),))
return {}
def _sendmail(self ,cr, uid, data, context):
self._update_partners(cr, uid, data, context)
mail_notsent = ''
count = 0
if data['form']['email_conf']:
pool = pooler.get_pool(cr.dbname)
data_user = pool.get('res.users').browse(cr,uid,uid)
line_obj = pool.get('account_followup.stat')
move_lines = line_obj.browse(cr,uid,data['form']['partner_ids'][0][2])
partners = []
dict_lines = {}
for line in move_lines:
partners.append(line.name)
dict_lines[line.name.id] =line
for partner in partners:
ids_lines = pool.get('account.move.line').search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable','payable'])])
data_lines = pool.get('account.move.line').browse(cr,uid,ids_lines)
followup_data = dict_lines[partner.id]
dest = False
if partner.address:
for adr in partner.address:
if adr.type=='contact':
if adr.email:
dest = [adr.email]
if (not dest) and adr.type=='default':
if adr.email:
dest = [adr.email]
src = tools.config.options['smtp_user']
body=data['form']['email_body']
total_amt = followup_data.debit - followup_data.credit
move_line = ''
subtotal_due = 0.0
subtotal_paid = 0.0
subtotal_maturity = 0.0
balance = 0.0
l = '--------------------------------------------------------------------------------------------------------------------------'
head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Maturity date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l
for i in data_lines:
maturity = ''
if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit):
maturity = i.debit - i.credit
subtotal_due = subtotal_due + i.debit
subtotal_paid = subtotal_paid + i.credit
subtotal_maturity = subtotal_maturity + int(maturity)
balance = balance + (i.debit - i.credit)
move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n'
move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n'
move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l
val = {
'partner_name':partner.name,
'followup_amount':total_amt,
'user_signature':data_user.name,
'company_name':data_user.company_id.name,
'line':move_line,
'heading': head,
'date':time.strftime('%Y-%m-%d')
}
body = body%val
sub = str(data['form']['email_subject'])
if dest:
tools.email_send(src,dest,sub,body)
count = count + 1
else:
mail_notsent = mail_notsent + partner.name + ','
return {'mail_notsent' : str(mail_notsent) , 'mail_sent' : str(count)}
def _sendmail(self ,cr, uid, data, context):
self._update_partners(cr, uid, data, context)
mail_notsent = ''
count = 0
if data['form']['email_conf']:
pool = pooler.get_pool(cr.dbname)
data_user = pool.get('res.users').browse(cr,uid,uid)
line_obj = pool.get('account_followup.stat')
move_lines = line_obj.browse(cr,uid,data['form']['partner_ids'][0][2])
partners = []
dict_lines = {}
for line in move_lines:
partners.append(line.name)
dict_lines[line.name.id] =line
for partner in partners:
ids_lines = pool.get('account.move.line').search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable','payable'])])
data_lines = pool.get('account.move.line').browse(cr,uid,ids_lines)
followup_data = dict_lines[partner.id]
dest = False
if partner.address:
for adr in partner.address:
if adr.type=='contact':
if adr.email:
dest = [adr.email]
if (not dest) and adr.type=='default':
if adr.email:
dest = [adr.email]
src = tools.config.options['smtp_user']
body=data['form']['email_body']
total_amt = followup_data.debit - followup_data.credit
move_line = ''
subtotal_due = 0.0
subtotal_paid = 0.0
subtotal_maturity = 0.0
balance = 0.0
l = '--------------------------------------------------------------------------------------------------------------------------'
head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Maturity date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l
for i in data_lines:
maturity = ''
if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit):
maturity = i.debit - i.credit
subtotal_due = subtotal_due + i.debit
subtotal_paid = subtotal_paid + i.credit
subtotal_maturity = subtotal_maturity + int(maturity)
balance = balance + (i.debit - i.credit)
move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n'
move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n'
move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l
val = {
'partner_name':partner.name,
'followup_amount':total_amt,
'user_signature':data_user.name,
'company_name':data_user.company_id.name,
'line':move_line,
'heading': head,
'date':time.strftime('%Y-%m-%d')
}
body = body%val
sub = str(data['form']['email_subject'])
if dest:
tools.email_send(src,dest,sub,body)
count = count + 1
else:
mail_notsent = mail_notsent + partner.name + ','
return {'mail_notsent' : str(mail_notsent) , 'mail_sent' : str(count)}
def _get_partners(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
cr.execute(
"SELECT l.partner_id, l.followup_line_id, l.date, l.id "\
"FROM account_move_line AS l "\
"LEFT JOIN account_account AS a "\
"ON (l.account_id=a.id) "\
"WHERE (l.reconcile_id IS NULL) "\
"AND (a.type='receivable') "\
"AND (l.state<>'draft') "\
"AND (l.reconcile_id is NULL) "\
"AND partner_id is NOT NULL "\
"AND a.active "\
"ORDER BY l.date")
move_lines = cr.fetchall()
def _get_partners(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
cr.execute(
"SELECT l.partner_id, l.followup_line_id, l.date, l.id "\
"FROM account_move_line AS l "\
"LEFT JOIN account_account AS a "\
"ON (l.account_id=a.id) "\
"WHERE (l.reconcile_id IS NULL) "\
"AND (a.type='receivable') "\
"AND (l.state<>'draft') "\
"AND (l.reconcile_id is NULL) "\
"AND partner_id is NOT NULL "\
"AND a.active "\
"ORDER BY l.date")
move_lines = cr.fetchall()
old = None
fups = {}
fup_ids = pool.get('account_followup.followup').search(cr, uid, [])
if not fup_ids:
raise wizard.except_wizard(_('No Follow up Defined'),
_('You must define at least one follow up for your company !'))
fup_id = fup_ids[0]
old = None
fups = {}
fup_ids = pool.get('account_followup.followup').search(cr, uid, [])
if not fup_ids:
raise wizard.except_wizard(_('No Follow up Defined'),
_('You must define at least one follow up for your company !'))
fup_id = fup_ids[0]
current_date = datetime.date(*time.strptime(data['form']['date'],
'%Y-%m-%d')[:3])
cr.execute(
"SELECT * "\
"FROM account_followup_followup_line "\
"WHERE followup_id=%d "\
"ORDER BY sequence", (fup_id,))
for result in cr.dictfetchall():
delay = datetime.timedelta(days=result['delay'])
fups[old] = (current_date - delay, result['id'])
if result['start'] == 'end_of_month':
fups[old][0].replace(day=1)
old = result['id']
current_date = datetime.date(*time.strptime(data['form']['date'],
'%Y-%m-%d')[:3])
cr.execute(
"SELECT * "\
"FROM account_followup_followup_line "\
"WHERE followup_id=%d "\
"ORDER BY sequence", (fup_id,))
for result in cr.dictfetchall():
delay = datetime.timedelta(days=result['delay'])
fups[old] = (current_date - delay, result['id'])
if result['start'] == 'end_of_month':
fups[old][0].replace(day=1)
old = result['id']
fups[old] = (datetime.date(datetime.MAXYEAR, 12, 31), old)
fups[old] = (datetime.date(datetime.MAXYEAR, 12, 31), old)
partner_list = []
to_update = {}
for partner_id, followup_line_id, date, id in move_lines:
if not partner_id:
continue
if partner_id in partner_list:
to_update[str(id)] = fups[followup_line_id][1]
if followup_line_id not in fups:
continue
if date <= fups[followup_line_id][0].strftime('%Y-%m-%d'):
partner_list.append(partner_id)
to_update[str(id)] = fups[followup_line_id][1]
return {'partner_ids': partner_list, 'to_update': to_update}
partner_list = []
to_update = {}
for partner_id, followup_line_id, date, id in move_lines:
if not partner_id:
continue
if partner_id in partner_list:
to_update[str(id)] = fups[followup_line_id][1]
if followup_line_id not in fups:
continue
if date <= fups[followup_line_id][0].strftime('%Y-%m-%d'):
partner_list.append(partner_id)
to_update[str(id)] = fups[followup_line_id][1]
return {'partner_ids': partner_list, 'to_update': to_update}
def _get_date(self, cursor, user, data, context):
return {'date': time.strftime('%Y-%m-%d')}
def _get_date(self, cursor, user, data, context):
return {'date': time.strftime('%Y-%m-%d')}
states = {
'init': {
'actions': [_get_date],
'result': {'type': 'form',
'arch': _followup_wizard_date_form,
'fields': _followup_wizard_date_fields,
'state': [
('end', 'Cancel'),
('next', 'Continue'),
]
},
},
'next': {
'actions': [_get_partners],
'result': {'type': 'form',
'arch': _followup_wizard_all_form,
'fields': _followup_wizard_all_fields,
'state': [
('end','Cancel'),
('print','Print Follow Ups'),
('sendmail','Send Mail')
]
},
},
'print': {
'actions': [_update_partners],
'result': {'type': 'print',
'report':'account_followup.followup.print',
'state':'end'},
},
'sendmail': {
'actions': [_sendmail],
'result': {'type': 'form',
'arch': form,
'fields': fields,
'state':[('end','Ok')]},
},
}
states = {
'init': {
'actions': [_get_date],
'result': {'type': 'form',
'arch': _followup_wizard_date_form,
'fields': _followup_wizard_date_fields,
'state': [
('end', 'Cancel'),
('next', 'Continue'),
]
},
},
'next': {
'actions': [_get_partners],
'result': {'type': 'form',
'arch': _followup_wizard_all_form,
'fields': _followup_wizard_all_fields,
'state': [
('end','Cancel'),
('print','Print Follow Ups'),
('sendmail','Send Mail')
]
},
},
'print': {
'actions': [_update_partners],
'result': {'type': 'print',
'report':'account_followup.followup.print',
'state':'end'},
},
'sendmail': {
'actions': [_sendmail],
'result': {'type': 'form',
'arch': form,
'fields': fields,
'state':[('end','Ok')]},
},
}
followup_all_print('account_followup.followup.print.all')

View File

@ -26,22 +26,22 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name": "Payment Management",
"version": "1.0",
"author": "Tiny",
"category": "Generic Modules/Payment",
"depends": ["account"],
"init_xml": [],
"description": """
This module provide :
* a more efficient way to manage invoice payment.
* a basic mechanism to easily plug various automated payment.
""",
"demo_xml": [],
"update_xml": ["payment_wizard.xml", "payment_view.xml",
"payment_workflow.xml", "payment_sequence.xml",
"account_invoice_view.xml", "payment_report.xml"],
"active": False,
"installable": True
"name": "Payment Management",
"version": "1.0",
"author": "Tiny",
"category": "Generic Modules/Payment",
"depends": ["account"],
"init_xml": [],
"description": """
This module provide :
* a more efficient way to manage invoice payment.
* a basic mechanism to easily plug various automated payment.
""",
"demo_xml": [],
"update_xml": ["payment_wizard.xml", "payment_view.xml",
"payment_workflow.xml", "payment_sequence.xml",
"account_invoice_view.xml", "payment_report.xml"],
"active": False,
"installable": True
}

View File

@ -31,28 +31,28 @@ from osv import fields, osv
from mx import DateTime
class Invoice(osv.osv):
_inherit = 'account.invoice'
_inherit = 'account.invoice'
def _amount_to_pay(self, cursor, user, ids, name, args, context=None):
'''Return the amount still to pay regarding all the payment orders'''
if not ids:
return {}
res = {}
for invoice in self.browse(cursor, user, ids, context=context):
res[invoice.id] = 0.0
if invoice.move_id:
for line in invoice.move_id.line_id:
if not line.date_maturity or \
DateTime.strptime(line.date_maturity, '%Y-%m-%d') \
< DateTime.now():
res[invoice.id] += line.amount_to_pay
return res
def _amount_to_pay(self, cursor, user, ids, name, args, context=None):
'''Return the amount still to pay regarding all the payment orders'''
if not ids:
return {}
res = {}
for invoice in self.browse(cursor, user, ids, context=context):
res[invoice.id] = 0.0
if invoice.move_id:
for line in invoice.move_id.line_id:
if not line.date_maturity or \
DateTime.strptime(line.date_maturity, '%Y-%m-%d') \
< DateTime.now():
res[invoice.id] += line.amount_to_pay
return res
_columns = {
'amount_to_pay': fields.function(_amount_to_pay, method=True,
type='float', string='Amount to be paid',
help='The amount which should be paid at the current date\n' \
'minus the amount which is already in payment order'),
}
_columns = {
'amount_to_pay': fields.function(_amount_to_pay, method=True,
type='float', string='Amount to be paid',
help='The amount which should be paid at the current date\n' \
'minus the amount which is already in payment order'),
}
Invoice()

View File

@ -18,12 +18,12 @@
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
@ -31,88 +31,88 @@ from osv import fields, osv
class account_move_line(osv.osv):
_inherit = "account.move.line"
_inherit = "account.move.line"
def amount_to_pay(self, cr, uid, ids, name, arg={}, context={}):
""" Return the amount still to pay regarding all the payemnt orders
(excepting cancelled orders)"""
if not ids:
return {}
cr.execute("""SELECT ml.id,
CASE WHEN ml.amount_currency < 0
THEN - ml.amount_currency
ELSE ml.credit
END -
(SELECT coalesce(sum(amount_currency),0)
FROM payment_line pl
INNER JOIN payment_order po
ON (pl.order_id = po.id)
WHERE move_line_id = ml.id
AND po.state != 'cancel') as amount
FROM account_move_line ml
WHERE id in (%s)""" % (",".join(map(str, ids))))
r=dict(cr.fetchall())
return r
def amount_to_pay(self, cr, uid, ids, name, arg={}, context={}):
""" Return the amount still to pay regarding all the payemnt orders
(excepting cancelled orders)"""
if not ids:
return {}
cr.execute("""SELECT ml.id,
CASE WHEN ml.amount_currency < 0
THEN - ml.amount_currency
ELSE ml.credit
END -
(SELECT coalesce(sum(amount_currency),0)
FROM payment_line pl
INNER JOIN payment_order po
ON (pl.order_id = po.id)
WHERE move_line_id = ml.id
AND po.state != 'cancel') as amount
FROM account_move_line ml
WHERE id in (%s)""" % (",".join(map(str, ids))))
r=dict(cr.fetchall())
return r
def _to_pay_search(self, cr, uid, obj, name, args):
if not len(args):
return []
line_obj = self.pool.get('account.move.line')
query = line_obj._query_get(cr, uid, context={})
where = ' and '.join(map(lambda x: '''(SELECT
CASE WHEN l.amount_currency < 0
THEN - l.amount_currency
ELSE l.credit
END - coalesce(sum(pl.amount_currency), 0)
FROM payment_line pl
INNER JOIN payment_order po ON (pl.order_id = po.id)
WHERE move_line_id = l.id AND po.state != 'cancel')''' \
+ x[1] + str(x[2])+' ',args))
def _to_pay_search(self, cr, uid, obj, name, args):
if not len(args):
return []
line_obj = self.pool.get('account.move.line')
query = line_obj._query_get(cr, uid, context={})
where = ' and '.join(map(lambda x: '''(SELECT
CASE WHEN l.amount_currency < 0
THEN - l.amount_currency
ELSE l.credit
END - coalesce(sum(pl.amount_currency), 0)
FROM payment_line pl
INNER JOIN payment_order po ON (pl.order_id = po.id)
WHERE move_line_id = l.id AND po.state != 'cancel')''' \
+ x[1] + str(x[2])+' ',args))
cr.execute(('''select id
from account_move_line l
where account_id in (select id
from account_account
where type=%s and active)
and reconcile_id is null
and credit > 0
and ''' + where + ' and ' + query), ('payable',) )
cr.execute(('''select id
from account_move_line l
where account_id in (select id
from account_account
where type=%s and active)
and reconcile_id is null
and credit > 0
and ''' + where + ' and ' + query), ('payable',) )
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
res = cr.fetchall()
if not len(res):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
def line2bank(self, cr, uid, ids, payment_type='manual', context=None):
"""
Try to return for each account move line a corresponding bank
account according to the payment type. This work using one of
the bank of the partner defined on the invoice eventually
associated to the line.
Return the first suitable bank for the corresponding partner.
"""
payment_mode_obj = self.pool.get('payment.mode')
line2bank = {}
if not ids:
return {}
bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
context=context)
for line in self.browse(cr, uid, ids, context=context):
line2bank[line.id] = False
if line.invoice and line.invoice.partner_bank:
line2bank[line.id] = line.invoice.partner_bank.id
elif line.partner_id:
for bank in line.partner_id.bank_ids:
if bank.state in bank_type:
line2bank[line.id] = bank.id
break
if line.id not in line2bank and line.partner_id.bank_ids:
line2bank[line.id] = line.partner_id.bank_ids[0].id
return line2bank
def line2bank(self, cr, uid, ids, payment_type='manual', context=None):
"""
Try to return for each account move line a corresponding bank
account according to the payment type. This work using one of
the bank of the partner defined on the invoice eventually
associated to the line.
Return the first suitable bank for the corresponding partner.
"""
payment_mode_obj = self.pool.get('payment.mode')
line2bank = {}
if not ids:
return {}
bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
context=context)
for line in self.browse(cr, uid, ids, context=context):
line2bank[line.id] = False
if line.invoice and line.invoice.partner_bank:
line2bank[line.id] = line.invoice.partner_bank.id
elif line.partner_id:
for bank in line.partner_id.bank_ids:
if bank.state in bank_type:
line2bank[line.id] = bank.id
break
if line.id not in line2bank and line.partner_id.bank_ids:
line2bank[line.id] = line.partner_id.bank_ids[0].id
return line2bank
_columns = {
'amount_to_pay' : fields.function(amount_to_pay, method=True,
type='float', string='Amount to pay', fnct_search=_to_pay_search),
}
_columns = {
'amount_to_pay' : fields.function(amount_to_pay, method=True,
type='float', string='Amount to pay', fnct_search=_to_pay_search),
}
account_move_line()

View File

@ -18,12 +18,12 @@
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
@ -35,471 +35,471 @@ import pooler
class payment_type(osv.osv):
_name= 'payment.type'
_description= 'Payment type'
_columns= {
'name': fields.char('Name', size=64, required=True),
'code': fields.char('Code', size=64, required=True),
'suitable_bank_types': fields.many2many('res.partner.bank.type',
'bank_type_payment_type_rel',
'pay_type_id','bank_type_id',
'Suitable bank types')
}
_name= 'payment.type'
_description= 'Payment type'
_columns= {
'name': fields.char('Name', size=64, required=True),
'code': fields.char('Code', size=64, required=True),
'suitable_bank_types': fields.many2many('res.partner.bank.type',
'bank_type_payment_type_rel',
'pay_type_id','bank_type_id',
'Suitable bank types')
}
payment_type()
class payment_mode(osv.osv):
_name= 'payment.mode'
_description= 'Payment mode'
_columns= {
'name': fields.char('Name', size=64, required=True),
'bank_id': fields.many2one('res.partner.bank', "Bank account",
required=True),
'journal': fields.many2one('account.journal', 'Journal', required=True,
domain=[('type', '=', 'cash')]),
'type': fields.many2one('payment.type','Payment type',required=True),
}
_name= 'payment.mode'
_description= 'Payment mode'
_columns= {
'name': fields.char('Name', size=64, required=True),
'bank_id': fields.many2one('res.partner.bank', "Bank account",
required=True),
'journal': fields.many2one('account.journal', 'Journal', required=True,
domain=[('type', '=', 'cash')]),
'type': fields.many2one('payment.type','Payment type',required=True),
}
def suitable_bank_types(self,cr,uid,payment_code= 'manual',context={}):
"""Return the codes of the bank type that are suitable
for the given payment type code"""
cr.execute(""" select t.code
from res_partner_bank_type t
join bank_type_payment_type_rel r on (r.bank_type_id = t.id)
join payment_type pt on (r.pay_type_id = pt.id)
where pt.code = %s """, [payment_code])
return [x[0] for x in cr.fetchall()]
def suitable_bank_types(self,cr,uid,payment_code= 'manual',context={}):
"""Return the codes of the bank type that are suitable
for the given payment type code"""
cr.execute(""" select t.code
from res_partner_bank_type t
join bank_type_payment_type_rel r on (r.bank_type_id = t.id)
join payment_type pt on (r.pay_type_id = pt.id)
where pt.code = %s """, [payment_code])
return [x[0] for x in cr.fetchall()]
payment_mode()
class payment_order(osv.osv):
_name = 'payment.order'
_description = 'Payment Order'
_rec_name = 'date'
_name = 'payment.order'
_description = 'Payment Order'
_rec_name = 'date'
def get_wizard(self,type):
logger = netsvc.Logger()
logger.notifyChannel("warning", netsvc.LOG_WARNING,
"No wizard found for the payment type '%s'." % type)
return None
def get_wizard(self,type):
logger = netsvc.Logger()
logger.notifyChannel("warning", netsvc.LOG_WARNING,
"No wizard found for the payment type '%s'." % type)
return None
def _total(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
res = {}
for order in self.browse(cursor, user, ids, context=context):
if order.line_ids:
res[order.id] = reduce(lambda x, y: x + y.amount, order.line_ids, 0.0)
else:
res[order.id] = 0.0
return res
def _total(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
res = {}
for order in self.browse(cursor, user, ids, context=context):
if order.line_ids:
res[order.id] = reduce(lambda x, y: x + y.amount, order.line_ids, 0.0)
else:
res[order.id] = 0.0
return res
_columns = {
'date_planned': fields.date('Scheduled date if fixed'),
'reference': fields.char('Reference',size=128,required=1),
'mode': fields.many2one('payment.mode','Payment mode', select=True, required=1),
'state': fields.selection([
('draft', 'Draft'),
('open','Confirmed'),
('cancel','Cancelled'),
('done','Done')], 'State', select=True),
'line_ids': fields.one2many('payment.line','order_id','Payment lines',states={'done':[('readonly',True)]}),
'total': fields.function(_total, string="Total", method=True,
type='float'),
'user_id': fields.many2one('res.users','User',required=True),
'date_prefered': fields.selection([
('now', 'Directly'),
('due', 'Due date'),
('fixed', 'Fixed date')
], "Prefered date", change_default=True, required=True),
'date_created': fields.date('Creation date', readonly=True),
'date_done': fields.date('Execution date', readonly=True),
}
_columns = {
'date_planned': fields.date('Scheduled date if fixed'),
'reference': fields.char('Reference',size=128,required=1),
'mode': fields.many2one('payment.mode','Payment mode', select=True, required=1),
'state': fields.selection([
('draft', 'Draft'),
('open','Confirmed'),
('cancel','Cancelled'),
('done','Done')], 'State', select=True),
'line_ids': fields.one2many('payment.line','order_id','Payment lines',states={'done':[('readonly',True)]}),
'total': fields.function(_total, string="Total", method=True,
type='float'),
'user_id': fields.many2one('res.users','User',required=True),
'date_prefered': fields.selection([
('now', 'Directly'),
('due', 'Due date'),
('fixed', 'Fixed date')
], "Prefered date", change_default=True, required=True),
'date_created': fields.date('Creation date', readonly=True),
'date_done': fields.date('Execution date', readonly=True),
}
_defaults = {
'user_id': lambda self,cr,uid,context: uid,
'state': lambda *a: 'draft',
'date_prefered': lambda *a: 'due',
'date_created': lambda *a: time.strftime('%Y-%m-%d'),
'reference': lambda self,cr,uid,context: self.pool.get('ir.sequence').get(cr, uid, 'payment.order'),
}
_defaults = {
'user_id': lambda self,cr,uid,context: uid,
'state': lambda *a: 'draft',
'date_prefered': lambda *a: 'due',
'date_created': lambda *a: time.strftime('%Y-%m-%d'),
'reference': lambda self,cr,uid,context: self.pool.get('ir.sequence').get(cr, uid, 'payment.order'),
}
def set_to_draft(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state':'draft'})
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_create(uid, 'payment.order', id, cr)
return True
def set_to_draft(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state':'draft'})
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_create(uid, 'payment.order', id, cr)
return True
def action_open(self, cr, uid, ids, *args):
for order in self.read(cr,uid,ids,['reference']):
if not order['reference']:
reference = self.pool.get('ir.sequence').get(cr, uid, 'payment.order')
self.write(cr,uid,order['id'],{'reference':reference})
return True
def action_open(self, cr, uid, ids, *args):
for order in self.read(cr,uid,ids,['reference']):
if not order['reference']:
reference = self.pool.get('ir.sequence').get(cr, uid, 'payment.order')
self.write(cr,uid,order['id'],{'reference':reference})
return True
def set_done(self, cr, uid, id, *args):
self.write(cr,uid,id,{'date_done': time.strftime('%Y-%m-%d'),
'state': 'done',})
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'payment.order', id, 'done', cr)
return True
def set_done(self, cr, uid, id, *args):
self.write(cr,uid,id,{'date_done': time.strftime('%Y-%m-%d'),
'state': 'done',})
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'payment.order', id, 'done', cr)
return True
payment_order()
class payment_line(osv.osv):
_name = 'payment.line'
_description = 'Payment Line'
_name = 'payment.line'
_description = 'Payment Line'
def partner_payable(self, cr, uid, ids, name, args, context={}):
if not ids: return {}
partners= self.read(cr, uid, ids, ['partner_id'], context)
partners= dict(map(lambda x: (x['id'], x['partner_id'][0]), partners))
debit = self.pool.get('res.partner')._debit_get(cr, uid,
partners.values(), name, args, context)
for i in partners:
partners[i] = debit[partners[i]]
return partners
def partner_payable(self, cr, uid, ids, name, args, context={}):
if not ids: return {}
partners= self.read(cr, uid, ids, ['partner_id'], context)
partners= dict(map(lambda x: (x['id'], x['partner_id'][0]), partners))
debit = self.pool.get('res.partner')._debit_get(cr, uid,
partners.values(), name, args, context)
for i in partners:
partners[i] = debit[partners[i]]
return partners
def translate(self, orig):
return {
# "to_pay": "credit",
"due_date": "date_maturity",
"reference": "ref"}.get(orig, orig)
def translate(self, orig):
return {
# "to_pay": "credit",
"due_date": "date_maturity",
"reference": "ref"}.get(orig, orig)
def info_owner(self, cr, uid, ids, name=None, args=None, context=None):
if not ids: return {}
result = {}
info=''
for line in self.browse(cr, uid, ids, context=context):
owner=line.order_id.mode.bank_id.partner_id
result[line.id]=False
if owner.address:
for ads in owner.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
cntry= ads.country_id and ads.country_id.name or ''
info=owner.name + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
result[line.id]=info
break
return result
def info_owner(self, cr, uid, ids, name=None, args=None, context=None):
if not ids: return {}
result = {}
info=''
for line in self.browse(cr, uid, ids, context=context):
owner=line.order_id.mode.bank_id.partner_id
result[line.id]=False
if owner.address:
for ads in owner.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
cntry= ads.country_id and ads.country_id.name or ''
info=owner.name + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
result[line.id]=info
break
return result
def info_partner(self, cr, uid, ids, name=None, args=None, context=None):
if not ids: return {}
result = {}
info=''
for line in self.browse(cr, uid, ids, context=context):
result[line.id]=False
if not line.partner_id:
break
partner = line.partner_id.name or ''
if line.partner_id.address:
for ads in line.partner_id.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
cntry= ads.country_id and ads.country_id.name or ''
info=partner + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
result[line.id]=info
break
return result
def info_partner(self, cr, uid, ids, name=None, args=None, context=None):
if not ids: return {}
result = {}
info=''
for line in self.browse(cr, uid, ids, context=context):
result[line.id]=False
if not line.partner_id:
break
partner = line.partner_id.name or ''
if line.partner_id.address:
for ads in line.partner_id.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
cntry= ads.country_id and ads.country_id.name or ''
info=partner + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
result[line.id]=info
break
return result
def select_by_name(self, cr, uid, ids, name, args, context=None):
if not ids: return {}
def select_by_name(self, cr, uid, ids, name, args, context=None):
if not ids: return {}
partner_obj = self.pool.get('res.partner')
cr.execute("""SELECT pl.id, ml.%s
from account_move_line ml
inner join payment_line pl
on (ml.id = pl.move_line_id)
where pl.id in (%s)"""%
(self.translate(name), ','.join(map(str,ids))) )
res = dict(cr.fetchall())
print "res: ", res
print "name ", name
partner_obj = self.pool.get('res.partner')
cr.execute("""SELECT pl.id, ml.%s
from account_move_line ml
inner join payment_line pl
on (ml.id = pl.move_line_id)
where pl.id in (%s)"""%
(self.translate(name), ','.join(map(str,ids))) )
res = dict(cr.fetchall())
print "res: ", res
print "name ", name
if name == 'partner_id':
partner_name = {}
for p_id, p_name in partner_obj.name_get(cr,uid,
filter(lambda x:x and x != 0,res.values()),context=context):
partner_name[p_id] = p_name
if name == 'partner_id':
partner_name = {}
for p_id, p_name in partner_obj.name_get(cr,uid,
filter(lambda x:x and x != 0,res.values()),context=context):
partner_name[p_id] = p_name
for id in ids:
if id in res and partner_name:
res[id] = (res[id],partner_name[res[id]])
else:
res[id] = (False,False)
else:
for id in ids:
res.setdefault(id, (False, ""))
return res
for id in ids:
if id in res and partner_name:
res[id] = (res[id],partner_name[res[id]])
else:
res[id] = (False,False)
else:
for id in ids:
res.setdefault(id, (False, ""))
return res
# def _currency(self, cursor, user, ids, name, args, context=None):
# if not ids:
# return {}
# res = {}
# def _currency(self, cursor, user, ids, name, args, context=None):
# if not ids:
# return {}
# res = {}
#
# currency_obj = self.pool.get('res.currency')
# account_obj = self.pool.get('account.account')
# cursor.execute('''SELECT pl.id, ml.currency_id, ml.account_id
# FROM account_move_line ml
# INNER JOIN payment_line pl
# ON (ml.id = pl.move_line_id)
# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
# currency_obj = self.pool.get('res.currency')
# account_obj = self.pool.get('account.account')
# cursor.execute('''SELECT pl.id, ml.currency_id, ml.account_id
# FROM account_move_line ml
# INNER JOIN payment_line pl
# ON (ml.id = pl.move_line_id)
# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
#
# res2 = {}
# account_ids = []
# for payment_line_id, currency_id, account_id in cursor.fetchall():
# res2[payment_line_id] = [currency_id, account_id]
# account_ids.append(account_id)
# res2 = {}
# account_ids = []
# for payment_line_id, currency_id, account_id in cursor.fetchall():
# res2[payment_line_id] = [currency_id, account_id]
# account_ids.append(account_id)
#
# account2currency_id = {}
# for account in account_obj.browse(cursor, user, account_ids,
# context=context):
# account2currency_id[account.id] = account.company_currency_id.id
# account2currency_id = {}
# for account in account_obj.browse(cursor, user, account_ids,
# context=context):
# account2currency_id[account.id] = account.company_currency_id.id
#
# for payment_line_id in ids:
# if res2[payment_line_id][0]:
# res[payment_line_id] = res2[payment_line_id][0]
# else:
# res[payment_line_id] = \
# account2currency_id[res2[payment_line_id][1]]
# for payment_line_id in ids:
# if res2[payment_line_id][0]:
# res[payment_line_id] = res2[payment_line_id][0]
# else:
# res[payment_line_id] = \
# account2currency_id[res2[payment_line_id][1]]
#
# currency_names = {}
# for currency_id, name in currency_obj.name_get(cursor, user, res.values(),
# context=context):
# currency_names[currency_id] = name
# for payment_line_id in ids:
# res[payment_line_id] = (res[payment_line_id],
# currency_names[res[payment_line_id]])
# return res
# currency_names = {}
# for currency_id, name in currency_obj.name_get(cursor, user, res.values(),
# context=context):
# currency_names[currency_id] = name
# for payment_line_id in ids:
# res[payment_line_id] = (res[payment_line_id],
# currency_names[res[payment_line_id]])
# return res
#
# def _to_pay_currency(self, cursor, user, ids, name , args, context=None):
# if not ids:
# return {}
# def _to_pay_currency(self, cursor, user, ids, name , args, context=None):
# if not ids:
# return {}
#
# cursor.execute('''SELECT pl.id,
# CASE WHEN ml.amount_currency < 0
# THEN - ml.amount_currency
# ELSE ml.credit
# END
# FROM account_move_line ml
# INNER JOIN payment_line pl
# ON (ml.id = pl.move_line_id)
# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
# return dict(cursor.fetchall())
# cursor.execute('''SELECT pl.id,
# CASE WHEN ml.amount_currency < 0
# THEN - ml.amount_currency
# ELSE ml.credit
# END
# FROM account_move_line ml
# INNER JOIN payment_line pl
# ON (ml.id = pl.move_line_id)
# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
# return dict(cursor.fetchall())
def _amount(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
currency_obj = self.pool.get('res.currency')
if context is None:
context = {}
res = {}
for line in self.browse(cursor, user, ids, context=context):
ctx = context.copy()
ctx['date'] = line.order_id.date_done or time.strftime('%Y-%m-%d')
res[line.id] = currency_obj.compute(cursor, user, line.currency.id,
line.company_currency.id,
line.amount_currency, context=ctx)
return res
def _amount(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
currency_obj = self.pool.get('res.currency')
if context is None:
context = {}
res = {}
for line in self.browse(cursor, user, ids, context=context):
ctx = context.copy()
ctx['date'] = line.order_id.date_done or time.strftime('%Y-%m-%d')
res[line.id] = currency_obj.compute(cursor, user, line.currency.id,
line.company_currency.id,
line.amount_currency, context=ctx)
return res
def _value_date(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
res = {}
for line in self.browse(cursor, user, ids, context=context):
if line.order_id.date_prefered == 'fixed':
res[line.id] = line.order_id.date_planned
elif line.order_id.date_prefered == 'due':
res[line.id] = line.due_date or time.strftime('%Y-%m-%d')
else:
res[line.id] = time.strftime('%Y-%m-%d')
return res
def _value_date(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
res = {}
for line in self.browse(cursor, user, ids, context=context):
if line.order_id.date_prefered == 'fixed':
res[line.id] = line.order_id.date_planned
elif line.order_id.date_prefered == 'due':
res[line.id] = line.due_date or time.strftime('%Y-%m-%d')
else:
res[line.id] = time.strftime('%Y-%m-%d')
return res
def _get_currency(self, cr, uid, context):
user = self.pool.get('res.users').browse(cr, uid, uid)
if user.company_id:
return user.company_id.currency_id.id
else:
return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
def _get_currency(self, cr, uid, context):
user = self.pool.get('res.users').browse(cr, uid, uid)
if user.company_id:
return user.company_id.currency_id.id
else:
return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
# def select_move_lines(*a):
# print a
# return []
# def select_move_lines(*a):
# print a
# return []
# def create(self, cr, uid, vals, context):
# print "created!!!"
# vals['company_currency'] = self._get_currency(cr, uid, context)
# return super(payment_line, self).create(cr, uid, vals, context)
# def create(self, cr, uid, vals, context):
# print "created!!!"
# vals['company_currency'] = self._get_currency(cr, uid, context)
# return super(payment_line, self).create(cr, uid, vals, context)
def _get_ml_inv_ref(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
res[id.id] = ""
print "test"
if id.move_line_id:
print "blablabl"
res[id.id] = "pas de invoice"
if id.move_line_id.invoice:
res[id.id] = str(id.move_line_id.invoice.number)
if id.move_line_id.invoice.name:
res[id.id] += " " + id.move_line_id.invoice.name
return res
def _get_ml_inv_ref(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
res[id.id] = ""
print "test"
if id.move_line_id:
print "blablabl"
res[id.id] = "pas de invoice"
if id.move_line_id.invoice:
res[id.id] = str(id.move_line_id.invoice.number)
if id.move_line_id.invoice.name:
res[id.id] += " " + id.move_line_id.invoice.name
return res
def _get_ml_maturity_date(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
if id.move_line_id:
res[id.id] = id.move_line_id.date_maturity
else:
res[id.id] = ""
return res
def _get_ml_maturity_date(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
if id.move_line_id:
res[id.id] = id.move_line_id.date_maturity
else:
res[id.id] = ""
return res
def _get_ml_created_date(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
if id.move_line_id:
res[id.id] = id.move_line_id.date_created
else:
res[id.id] = ""
return res
def _get_ml_created_date(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
if id.move_line_id:
res[id.id] = id.move_line_id.date_created
else:
res[id.id] = ""
return res
_columns = {
'name': fields.char('Your Reference', size=64, required=True),
'communication': fields.char('Communication', size=64, required=True),
'communication2': fields.char('Communication 2', size=64),
'move_line_id': fields.many2one('account.move.line','Entry line', domain=[('reconcile_id','=', False), ('account_id.type', '=','payable')]),
'amount_currency': fields.float('Amount', digits=(16,2),
required=True, help='Payment amount in the partner currency'),
# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
# method=True, type='float',
# help='Amount to pay in the partner currency'),
# 'currency': fields.function(_currency, string='Currency',
# method=True, type='many2one', obj='res.currency'),
'currency': fields.many2one('res.currency','Currency',required=True),
'company_currency': fields.many2one('res.currency','Currency',readonly=True),
'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),
'order_id': fields.many2one('payment.order', 'Order', required=True,
ondelete='cascade', select=True),
'partner_id': fields.many2one('res.partner', string="Partner",required=True),
'amount': fields.function(_amount, string='Amount',
method=True, type='float',
help='Payment amount in the company currency'),
# 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
# type='float', help='Amount to pay in the company currency'),
# 'due_date': fields.function(select_by_name, string="Due date",
# method=True, type='date'),
'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",
method=True, type='date',help="Invoice Effective Date"),
# 'reference': fields.function(select_by_name, string="Ref", method=True,
# type='char'),
'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='char', string='Maturity Date'),
'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='char', string='Invoice Ref'),
'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text"),
'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text"),
'partner_payable': fields.function(partner_payable,
string="Partner payable", method=True, type='float'),
# 'value_date': fields.function(_value_date, string='Value Date',
# method=True, type='date'),
'date': fields.date('Payment Date'),
'create_date': fields.datetime('Created' ,readonly=True),
'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)
}
_defaults = {
'name': lambda obj, cursor, user, context: obj.pool.get('ir.sequence'
).get(cursor, user, 'payment.line'),
'state': lambda *args: 'normal',
'currency': _get_currency,
'company_currency': _get_currency,
}
_sql_constraints = [
('name_uniq', 'UNIQUE(name)', 'The payment line name must be unique!'),
]
_columns = {
'name': fields.char('Your Reference', size=64, required=True),
'communication': fields.char('Communication', size=64, required=True),
'communication2': fields.char('Communication 2', size=64),
'move_line_id': fields.many2one('account.move.line','Entry line', domain=[('reconcile_id','=', False), ('account_id.type', '=','payable')]),
'amount_currency': fields.float('Amount', digits=(16,2),
required=True, help='Payment amount in the partner currency'),
# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
# method=True, type='float',
# help='Amount to pay in the partner currency'),
# 'currency': fields.function(_currency, string='Currency',
# method=True, type='many2one', obj='res.currency'),
'currency': fields.many2one('res.currency','Currency',required=True),
'company_currency': fields.many2one('res.currency','Currency',readonly=True),
'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),
'order_id': fields.many2one('payment.order', 'Order', required=True,
ondelete='cascade', select=True),
'partner_id': fields.many2one('res.partner', string="Partner",required=True),
'amount': fields.function(_amount, string='Amount',
method=True, type='float',
help='Payment amount in the company currency'),
# 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
# type='float', help='Amount to pay in the company currency'),
# 'due_date': fields.function(select_by_name, string="Due date",
# method=True, type='date'),
'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",
method=True, type='date',help="Invoice Effective Date"),
# 'reference': fields.function(select_by_name, string="Ref", method=True,
# type='char'),
'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='char', string='Maturity Date'),
'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='char', string='Invoice Ref'),
'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text"),
'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text"),
'partner_payable': fields.function(partner_payable,
string="Partner payable", method=True, type='float'),
# 'value_date': fields.function(_value_date, string='Value Date',
# method=True, type='date'),
'date': fields.date('Payment Date'),
'create_date': fields.datetime('Created' ,readonly=True),
'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)
}
_defaults = {
'name': lambda obj, cursor, user, context: obj.pool.get('ir.sequence'
).get(cursor, user, 'payment.line'),
'state': lambda *args: 'normal',
'currency': _get_currency,
'company_currency': _get_currency,
}
_sql_constraints = [
('name_uniq', 'UNIQUE(name)', 'The payment line name must be unique!'),
]
def onchange_move_line(self,cr,uid,ids,move_line_id,payment_type,context=None):
data={}
data['amount_currency']=data['currency']=data['communication']=data['partner_id']=data['reference']=data['date_created']=data['bank_id']=False
if move_line_id:
line=self.pool.get('account.move.line').browse(cr,uid,move_line_id)
data['amount_currency']=line.amount_to_pay
data['partner_id']=line.partner_id.id
data['currency']=line.currency_id and line.currency_id.id or False
if not data['currency']:
data['currency']=line.invoice and line.invoice.currency_id.id or False
# calling onchange of partner and updating data dictionary
temp_dict=self.onchange_partner(cr,uid,ids,line.partner_id.id)
data.update(temp_dict['value'])
def onchange_move_line(self,cr,uid,ids,move_line_id,payment_type,context=None):
data={}
data['amount_currency']=data['currency']=data['communication']=data['partner_id']=data['reference']=data['date_created']=data['bank_id']=False
if move_line_id:
line=self.pool.get('account.move.line').browse(cr,uid,move_line_id)
data['amount_currency']=line.amount_to_pay
data['partner_id']=line.partner_id.id
data['currency']=line.currency_id and line.currency_id.id or False
if not data['currency']:
data['currency']=line.invoice and line.invoice.currency_id.id or False
# calling onchange of partner and updating data dictionary
temp_dict=self.onchange_partner(cr,uid,ids,line.partner_id.id)
data.update(temp_dict['value'])
data['reference']=line.ref
data['date_created']=line.date_created
data['communication']=line.ref
data['reference']=line.ref
data['date_created']=line.date_created
data['communication']=line.ref
if payment_type:
payment_mode = self.pool.get('payment.mode').browse(cr,uid,payment_type).type.code
else:
payment_mode=False
if payment_type:
payment_mode = self.pool.get('payment.mode').browse(cr,uid,payment_type).type.code
else:
payment_mode=False
# data['bank_id']=self.pool.get('account.move.line').line2bank(cr, uid,
# [move_line_id],
# payment_mode or 'manual', context)[move_line_id]
# data['bank_id']=self.pool.get('account.move.line').line2bank(cr, uid,
# [move_line_id],
# payment_mode or 'manual', context)[move_line_id]
return {'value': data}
return {'value': data}
def onchange_partner(self,cr,uid,ids,partner_id,context=None):
data={}
data['info_partner']=data['bank_id']=False
def onchange_partner(self,cr,uid,ids,partner_id,context=None):
data={}
data['info_partner']=data['bank_id']=False
if partner_id:
part_obj=self.pool.get('res.partner').browse(cr,uid,partner_id)
partner=part_obj.name or ''
if partner_id:
part_obj=self.pool.get('res.partner').browse(cr,uid,partner_id)
partner=part_obj.name or ''
if part_obj.address:
for ads in part_obj.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if part_obj.address:
for ads in part_obj.address:
if ads.type=='default':
st=ads.street and ads.street or ''
st1=ads.street2 and ads.street2 or ''
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
if 'zip_id' in ads:
zip_city= ads.zip_id and self.pool.get('res.partner.zip').name_get(cr,uid,[ads.zip_id.id])[0][1] or ''
else:
zip=ads.zip and ads.zip or ''
city= ads.city and ads.city or ''
zip_city= zip + ' ' + city
cntry= ads.country_id and ads.country_id.name or ''
info=partner + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
cntry= ads.country_id and ads.country_id.name or ''
info=partner + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
data['info_partner']=info
data['info_partner']=info
if part_obj.bank_ids and len(part_obj.bank_ids)==1:
data['bank_id']=self.pool.get('res.partner.bank').name_get(cr,uid,[part_obj.bank_ids[0].id])[0][0]
if part_obj.bank_ids and len(part_obj.bank_ids)==1:
data['bank_id']=self.pool.get('res.partner.bank').name_get(cr,uid,[part_obj.bank_ids[0].id])[0][0]
return {'value': data}
return {'value': data}
def fields_get(self, cr, uid, fields=None, context=None):
res = super(payment_line, self).fields_get(cr, uid, fields, context)
if 'communication2' in res:
res['communication2'].setdefault('states', {})
res['communication2']['states']['structured'] = [('readonly', True)]
res['communication2']['states']['normal'] = [('readonly', False)]
def fields_get(self, cr, uid, fields=None, context=None):
res = super(payment_line, self).fields_get(cr, uid, fields, context)
if 'communication2' in res:
res['communication2'].setdefault('states', {})
res['communication2']['states']['structured'] = [('readonly', True)]
res['communication2']['states']['normal'] = [('readonly', False)]
return res
return res
payment_line()

View File

@ -35,39 +35,39 @@ import time
def _launch_wizard(self, cr, uid, data, context):
"""
Search for a wizard to launch according to the type.
If type is manual. just confirm the order.
"""
"""
Search for a wizard to launch according to the type.
If type is manual. just confirm the order.
"""
order_ref= pooler.get_pool(cr.dbname).get('payment.order')
order= order_ref.browse(cr,uid,data['id'],context)
t= order.mode and order.mode.type.code or 'manual'
if t == 'manual' :
order_ref.set_done(cr,uid,data['id'],context)
return {}
order_ref= pooler.get_pool(cr.dbname).get('payment.order')
order= order_ref.browse(cr,uid,data['id'],context)
t= order.mode and order.mode.type.code or 'manual'
if t == 'manual' :
order_ref.set_done(cr,uid,data['id'],context)
return {}
gw= order_ref.get_wizard(t)
if not gw:
order_ref.set_done(cr,uid,data['id'],context)
return {}
gw= order_ref.get_wizard(t)
if not gw:
order_ref.set_done(cr,uid,data['id'],context)
return {}
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.wizard')
module, wizard= gw
result = mod_obj._get_id(cr, uid, module, wizard)
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
#result['context'] = str({'fiscalyear': data['form']['fiscalyear']})
return result
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.wizard')
module, wizard= gw
result = mod_obj._get_id(cr, uid, module, wizard)
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
#result['context'] = str({'fiscalyear': data['form']['fiscalyear']})
return result
class wizard_pay(wizard.interface):
states= {'init' : {'actions': [],
'result':{'type':'action',
'action':_launch_wizard,
'state':'end'}
}
}
states= {'init' : {'actions': [],
'result':{'type':'action',
'action':_launch_wizard,
'state':'end'}
}
}
wizard_pay('pay_payment')

View File

@ -35,12 +35,12 @@ import time
FORM = UpdateableStr()
FIELDS = {
'entries': {'string':'Entries', 'type':'many2many',
'relation': 'account.move.line',},
'entries': {'string':'Entries', 'type':'many2many',
'relation': 'account.move.line',},
}
field_duedate={
'duedate': {'string':'Due Date', 'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d'),},
}
'duedate': {'string':'Due Date', 'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d'),},
}
arch_duedate='''<?xml version="1.0"?>
<form string="Search Payment lines">
<field name="duedate" />
@ -48,103 +48,103 @@ arch_duedate='''<?xml version="1.0"?>
def search_entries(self, cr, uid, data, context):
search_due_date=data['form']['duedate']
search_due_date=data['form']['duedate']
pool = pooler.get_pool(cr.dbname)
order_obj = pool.get('payment.order')
line_obj = pool.get('account.move.line')
pool = pooler.get_pool(cr.dbname)
order_obj = pool.get('payment.order')
line_obj = pool.get('account.move.line')
payment = order_obj.browse(cr, uid, data['id'],
context=context)
ctx = ''
if payment.mode:
ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id
payment = order_obj.browse(cr, uid, data['id'],
context=context)
ctx = ''
if payment.mode:
ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id
# Search for move line to pay:
line_ids = line_obj.search(cr, uid, [
('reconcile_id', '=', False),
('amount_to_pay', '>', 0),('date_maturity','<=',search_due_date)], context=context)
# Search for move line to pay:
line_ids = line_obj.search(cr, uid, [
('reconcile_id', '=', False),
('amount_to_pay', '>', 0),('date_maturity','<=',search_due_date)], context=context)
FORM.string = '''<?xml version="1.0"?>
FORM.string = '''<?xml version="1.0"?>
<form string="Populate Payment:">
<field name="entries" colspan="4" height="300" width="800" nolabel="1"
domain="[('id', 'in', [%s])]" %s/>
<field name="entries" colspan="4" height="300" width="800" nolabel="1"
domain="[('id', 'in', [%s])]" %s/>
</form>''' % (','.join([str(x) for x in line_ids]), ctx)
return {'entries': line_ids}
return {'entries': line_ids}
def create_payment(self, cr, uid, data, context):
line_ids= data['form']['entries'][0][2]
if not line_ids: return {}
line_ids= data['form']['entries'][0][2]
if not line_ids: return {}
pool= pooler.get_pool(cr.dbname)
order_obj = pool.get('payment.order')
line_obj = pool.get('account.move.line')
pool= pooler.get_pool(cr.dbname)
order_obj = pool.get('payment.order')
line_obj = pool.get('account.move.line')
payment = order_obj.browse(cr, uid, data['id'],
context=context)
t = payment.mode and payment.mode.type.code or 'manual'
line2bank= pool.get('account.move.line').line2bank(cr, uid,
line_ids, t, context)
payment = order_obj.browse(cr, uid, data['id'],
context=context)
t = payment.mode and payment.mode.type.code or 'manual'
line2bank= pool.get('account.move.line').line2bank(cr, uid,
line_ids, t, context)
## Finally populate the current payment with new lines:
for line in line_obj.browse(cr, uid, line_ids, context=context):
pool.get('payment.line').create(cr,uid,{
'move_line_id': line.id,
'amount_currency': line.amount_to_pay,
'bank_id': line2bank.get(line.id),
'order_id': payment.id,
'partner_id': line.partner_id and line.partner_id.id or False,
'communication': line.ref or '/'
}, context=context)
return {}
## Finally populate the current payment with new lines:
for line in line_obj.browse(cr, uid, line_ids, context=context):
pool.get('payment.line').create(cr,uid,{
'move_line_id': line.id,
'amount_currency': line.amount_to_pay,
'bank_id': line2bank.get(line.id),
'order_id': payment.id,
'partner_id': line.partner_id and line.partner_id.id or False,
'communication': line.ref or '/'
}, context=context)
return {}
class wizard_payment_order(wizard.interface):
"""
Create a payment object with lines corresponding to the account move line
to pay according to the date and the mode provided by the user.
Hypothesis:
- Small number of non-reconcilied move line , payment mode and bank account type,
- Big number of partner and bank account.
"""
Create a payment object with lines corresponding to the account move line
to pay according to the date and the mode provided by the user.
Hypothesis:
- Small number of non-reconcilied move line , payment mode and bank account type,
- Big number of partner and bank account.
If a type is given, unsuitable account move lines are ignored.
"""
states = {
If a type is given, unsuitable account move lines are ignored.
"""
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': arch_duedate,
'fields':field_duedate,
'state': [
('end','_Cancel'),
('search','_Search', '', True)
]
},
},
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': arch_duedate,
'fields':field_duedate,
'state': [
('end','_Cancel'),
('search','_Search', '', True)
]
},
},
'search': {
'actions': [search_entries],
'result': {
'type': 'form',
'arch': FORM,
'fields': FIELDS,
'state': [
('end','_Cancel'),
('create','_Add to payment order', '', True)
]
},
},
'create': {
'actions': [],
'result': {
'type': 'action',
'action': create_payment,
'state': 'end'}
},
}
'search': {
'actions': [search_entries],
'result': {
'type': 'form',
'arch': FORM,
'fields': FIELDS,
'state': [
('end','_Cancel'),
('create','_Add to payment order', '', True)
]
},
},
'create': {
'actions': [],
'result': {
'type': 'action',
'action': create_payment,
'state': 'end'}
},
}
wizard_payment_order('populate_payment')

View File

@ -33,91 +33,91 @@ from tools.misc import UpdateableStr
FORM = UpdateableStr()
FIELDS = {
'lines': {'string': 'Payment Lines', 'type': 'many2many',
'relation': 'payment.line'},
'lines': {'string': 'Payment Lines', 'type': 'many2many',
'relation': 'payment.line'},
}
def _search_entries(obj, cursor, user, data, context):
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.line')
statement_obj = pool.get('account.bank.statement')
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.line')
statement_obj = pool.get('account.bank.statement')
statement = statement_obj.browse(cursor, user, data['id'], context=context)
statement = statement_obj.browse(cursor, user, data['id'], context=context)
line_ids = line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode.journal.id', '=', statement.journal_id.id)])
line_ids.extend(line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode', '=', False)]))
line_ids = line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode.journal.id', '=', statement.journal_id.id)])
line_ids.extend(line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode', '=', False)]))
FORM.string = '''<?xml version="1.0"?>
FORM.string = '''<?xml version="1.0"?>
<form string="Populate Statement:">
<field name="lines" colspan="4" height="300" width="800" nolabel="1"
domain="[('id', 'in', [%s])]"/>
<field name="lines" colspan="4" height="300" width="800" nolabel="1"
domain="[('id', 'in', [%s])]"/>
</form>''' % (','.join([str(x) for x in line_ids]))
return {}
return {}
def _populate_statement(obj, cursor, user, data, context):
line_ids = data['form']['lines'][0][2]
if not line_ids:
return {}
line_ids = data['form']['lines'][0][2]
if not line_ids:
return {}
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.line')
statement_obj = pool.get('account.bank.statement')
statement_line_obj = pool.get('account.bank.statement.line')
currency_obj = pool.get('res.currency')
statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.line')
statement_obj = pool.get('account.bank.statement')
statement_line_obj = pool.get('account.bank.statement.line')
currency_obj = pool.get('res.currency')
statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
statement = statement_obj.browse(cursor, user, data['id'], context=context)
statement = statement_obj.browse(cursor, user, data['id'], context=context)
for line in line_obj.browse(cursor, user, line_ids, context=context):
ctx = context.copy()
ctx['date'] = line.value_date
amount = currency_obj.compute(cursor, user, line.currency.id,
statement.currency.id, line.amount_currency, context=ctx)
reconcile_id = statement_reconcile_obj.create(cursor, user, {
'line_ids': [(6, 0, [line.move_line_id.id])]
}, context=context)
statement_line_obj.create(cursor, user, {
'name': line.order_id.reference or '?',
'amount': - amount,
'type': 'supplier',
'partner_id': line.partner_id.id,
'account_id': line.move_line_id.account_id.id,
'statement_id': statement.id,
'ref': line.reference,
'reconcile_id': reconcile_id,
}, context=context)
return {}
for line in line_obj.browse(cursor, user, line_ids, context=context):
ctx = context.copy()
ctx['date'] = line.value_date
amount = currency_obj.compute(cursor, user, line.currency.id,
statement.currency.id, line.amount_currency, context=ctx)
reconcile_id = statement_reconcile_obj.create(cursor, user, {
'line_ids': [(6, 0, [line.move_line_id.id])]
}, context=context)
statement_line_obj.create(cursor, user, {
'name': line.order_id.reference or '?',
'amount': - amount,
'type': 'supplier',
'partner_id': line.partner_id.id,
'account_id': line.move_line_id.account_id.id,
'statement_id': statement.id,
'ref': line.reference,
'reconcile_id': reconcile_id,
}, context=context)
return {}
class PopulateStatement(wizard.interface):
"""
Populate the current statement with selected payement lines
"""
states = {
'init': {
'actions': [_search_entries],
'result': {
'type': 'form',
'arch': FORM,
'fields': FIELDS,
'state': [
('end', '_Cancel'),
('add', '_Add', '', True)
]
},
},
'add': {
'actions': [],
'result': {
'type': 'action',
'action': _populate_statement,
'state': 'end'
},
},
}
"""
Populate the current statement with selected payement lines
"""
states = {
'init': {
'actions': [_search_entries],
'result': {
'type': 'form',
'arch': FORM,
'fields': FIELDS,
'state': [
('end', '_Cancel'),
('add', '_Add', '', True)
]
},
},
'add': {
'actions': [],
'result': {
'type': 'action',
'action': _populate_statement,
'state': 'end'
},
},
}
PopulateStatement('populate_statement')

View File

@ -26,19 +26,19 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Reporting for accounting",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """Financial and accounting reporting""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ "account_view.xml","account_report.xml" ],
# "translations" : {
# "fr": "i18n/french_fr.csv"
# },
"active": False,
"installable": True
"name" : "Reporting for accounting",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """Financial and accounting reporting""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ "account_view.xml","account_report.xml" ],
# "translations" : {
# "fr": "i18n/french_fr.csv"
# },
"active": False,
"installable": True
}

View File

@ -38,141 +38,141 @@ from mx.DateTime import RelativeDateTime, now, DateTime, localtime
class account_report(osv.osv):
_name = "account.report.report"
_description = "Account reporting"
_color = [
('', ''),
('green','Green'),
('red','Red'),
('pink','Pink'),
('blue','Blue'),
('yellow','Yellow'),
('cyan','Cyan'),
('lightblue','Light Blue'),
('orange','Orange'),
]
_style = [
('1','Header 1'),
('2','Header 2'),
('3','Header 3'),
('4','Header 4'),
('5','Normal'),
('6', 'Small'),
]
_name = "account.report.report"
_description = "Account reporting"
_color = [
('', ''),
('green','Green'),
('red','Red'),
('pink','Pink'),
('blue','Blue'),
('yellow','Yellow'),
('cyan','Cyan'),
('lightblue','Light Blue'),
('orange','Orange'),
]
_style = [
('1','Header 1'),
('2','Header 2'),
('3','Header 3'),
('4','Header 4'),
('5','Normal'),
('6', 'Small'),
]
def _amount_get(self, cr, uid, ids, field_name, arg, context={}):
def _calc_credit(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.credit+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_debit(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.debit+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_balance(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.balance+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_report(*code):
acc = self.pool.get('account.report.report')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.amount+y, acc.browse(cr, uid, acc_id, context),0)
result = {}
for rep in self.browse(cr, uid, ids, context):
objdict = {
'debit': _calc_debit,
'credit': _calc_credit,
'balance': _calc_balance,
'report': _calc_report,
}
if field_name=='status':
fld_name = 'expression_status'
else:
fld_name = 'expression'
try:
val = eval(getattr(rep, fld_name), objdict)
except:
val = 0.0
if field_name=='status':
if val<-1:
result[rep.id] = 'very bad'
elif val<0:
result[rep.id] = 'bad'
elif val==0:
result[rep.id] = 'normal'
elif val<1:
result[rep.id] = 'good'
else:
result[rep.id] = 'excellent'
else:
result[rep.id] = val
return result
def _amount_get(self, cr, uid, ids, field_name, arg, context={}):
def _calc_credit(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.credit+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_debit(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.debit+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_balance(*code):
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.balance+y, acc.browse(cr, uid, acc_id, context),0)
def _calc_report(*code):
acc = self.pool.get('account.report.report')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.amount+y, acc.browse(cr, uid, acc_id, context),0)
result = {}
for rep in self.browse(cr, uid, ids, context):
objdict = {
'debit': _calc_debit,
'credit': _calc_credit,
'balance': _calc_balance,
'report': _calc_report,
}
if field_name=='status':
fld_name = 'expression_status'
else:
fld_name = 'expression'
try:
val = eval(getattr(rep, fld_name), objdict)
except:
val = 0.0
if field_name=='status':
if val<-1:
result[rep.id] = 'very bad'
elif val<0:
result[rep.id] = 'bad'
elif val==0:
result[rep.id] = 'normal'
elif val<1:
result[rep.id] = 'good'
else:
result[rep.id] = 'excellent'
else:
result[rep.id] = val
return result
def onchange_parent_id(self, cr, uid, ids, parent_id):
v={}
if parent_id:
acc=self.pool.get('account.report.report').browse(cr,uid,parent_id)
v['type']=acc.type
if int(acc.style) < 6:
v['style'] = str(int(acc.style)+1)
return {'value': v}
def onchange_parent_id(self, cr, uid, ids, parent_id):
v={}
if parent_id:
acc=self.pool.get('account.report.report').browse(cr,uid,parent_id)
v['type']=acc.type
if int(acc.style) < 6:
v['style'] = str(int(acc.style)+1)
return {'value': v}
_columns = {
'name': fields.char('Name', size=64, required=True),
'active': fields.boolean('Active'),
'sequence': fields.integer('Sequence'),
'code': fields.char('Code', size=64, required=True),
'type': fields.selection([
('fiscal', 'Fiscal statement'),
('indicator','Indicator'),
('other','Others')],
'Type', required=True),
'expression': fields.char('Expression', size=240, required=True),
'expression_status': fields.char('Status expression', size=240, required=True),
'parent_id': fields.many2one('account.report.report', 'Parent'),
'child_ids': fields.one2many('account.report.report', 'parent_id', 'Childs'),
'note': fields.text('Note'),
'amount': fields.function(_amount_get, method=True, string='Value'),
'status': fields.function(_amount_get,
method=True,
type="selection",
selection=[
('very bad', 'Very Bad'),
('bad', 'Bad'),
('normal', ''),
('good', 'Good'),
('excellent', 'Excellent')
],
string='Status'),
'style': fields.selection(_style, 'Style', required=True),
'color_font' : fields.selection(_color, 'Font Color', help="Font Color for the report"),
'color_back' : fields.selection(_color, 'Back Color')
}
_defaults = {
'style': lambda *args: '5',
'active': lambda *args: True,
'type': lambda *args: 'indicator',
}
_columns = {
'name': fields.char('Name', size=64, required=True),
'active': fields.boolean('Active'),
'sequence': fields.integer('Sequence'),
'code': fields.char('Code', size=64, required=True),
'type': fields.selection([
('fiscal', 'Fiscal statement'),
('indicator','Indicator'),
('other','Others')],
'Type', required=True),
'expression': fields.char('Expression', size=240, required=True),
'expression_status': fields.char('Status expression', size=240, required=True),
'parent_id': fields.many2one('account.report.report', 'Parent'),
'child_ids': fields.one2many('account.report.report', 'parent_id', 'Childs'),
'note': fields.text('Note'),
'amount': fields.function(_amount_get, method=True, string='Value'),
'status': fields.function(_amount_get,
method=True,
type="selection",
selection=[
('very bad', 'Very Bad'),
('bad', 'Bad'),
('normal', ''),
('good', 'Good'),
('excellent', 'Excellent')
],
string='Status'),
'style': fields.selection(_style, 'Style', required=True),
'color_font' : fields.selection(_color, 'Font Color', help="Font Color for the report"),
'color_back' : fields.selection(_color, 'Back Color')
}
_defaults = {
'style': lambda *args: '5',
'active': lambda *args: True,
'type': lambda *args: 'indicator',
}
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
if not args:
args=[]
if not context:
context={}
ids = []
if name:
ids = self.search(cr, user, [('code','=',name)]+ args, limit=limit, context=context)
if not ids:
ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
else:
ids = self.search(cr, user, args, limit=limit, context=context)
return self.name_get(cr, user, ids, context=context)
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
if not args:
args=[]
if not context:
context={}
ids = []
if name:
ids = self.search(cr, user, [('code','=',name)]+ args, limit=limit, context=context)
if not ids:
ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
else:
ids = self.search(cr, user, args, limit=limit, context=context)
return self.name_get(cr, user, ids, context=context)
_constraints = [
#TODO Put an expression to valid expression and expression_status
]
_sql_constraints = [
('code_uniq', 'unique (code)', 'The code of the report entry must be unique !')
]
_constraints = [
#TODO Put an expression to valid expression and expression_status
]
_sql_constraints = [
('code_uniq', 'unique (code)', 'The code of the report entry must be unique !')
]
account_report()

0
addons/account_report/report/__init__.py Executable file → Normal file
View File

48
addons/account_report/report/accounting_report.py Executable file → Normal file
View File

@ -34,33 +34,33 @@ from report import report_sxw
class accounting_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(accounting_report, self).__init__(cr, uid, name, context)
self.ret_list = []
self.localcontext.update({
'time': time,
'childs':self.process
})
def __init__(self, cr, uid, name, context):
super(accounting_report, self).__init__(cr, uid, name, context)
self.ret_list = []
self.localcontext.update({
'time': time,
'childs':self.process
})
def process(self,id,level=0):
res = pooler.get_pool(self.cr.dbname).get('account.report.report').read(self.cr,self.uid,[id])
ret_dict={
'name':res[0]['name'],
'code':res[0]['code'],
'amount':res[0]['amount'],
'note':res[0]['note'],
'level': level,
'color_font':res[0]['color_font'],
'color_back':res[0]['color_back'],
}
def process(self,id,level=0):
res = pooler.get_pool(self.cr.dbname).get('account.report.report').read(self.cr,self.uid,[id])
ret_dict={
'name':res[0]['name'],
'code':res[0]['code'],
'amount':res[0]['amount'],
'note':res[0]['note'],
'level': level,
'color_font':res[0]['color_font'],
'color_back':res[0]['color_back'],
}
self.ret_list.append(ret_dict)
for child_id in res[0]['child_ids']:
self.process(child_id,level+1)
return self.ret_list
self.ret_list.append(ret_dict)
for child_id in res[0]['child_ids']:
self.process(child_id,level+1)
return self.ret_list
report_sxw.report_sxw('report.accounting.report', 'account.report.report',
'addons/account_report/report/accounting_report.rml',
parser=accounting_report, header=False)
'addons/account_report/report/accounting_report.rml',
parser=accounting_report, header=False)

View File

@ -26,20 +26,20 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Invoices and prices with taxes included",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """Allow the user to work tax included prices.
"name" : "Invoices and prices with taxes included",
"version" : "1.0",
"depends" : ["account"],
"author" : "Tiny",
"description": """Allow the user to work tax included prices.
Especially useful for b2c businesses.
This module implement the modification on the invoice form.
""",
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ 'invoice_tax_incl.xml' ],
"active": False,
"installable": True
"website" : "http://tinyerp.com/module_account.html",
"category" : "Generic Modules/Accounting",
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ 'invoice_tax_incl.xml' ],
"active": False,
"installable": True
}

View File

@ -34,183 +34,183 @@ from osv import fields, osv
import ir
class account_invoice(osv.osv):
def _amount_untaxed(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id] = reduce( lambda x, y: x+y.price_subtotal, invoice.invoice_line,0)
else:
res[invoice.id] = super(account_invoice, self)._amount_untaxed(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
def _amount_untaxed(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id] = reduce( lambda x, y: x+y.price_subtotal, invoice.invoice_line,0)
else:
res[invoice.id] = super(account_invoice, self)._amount_untaxed(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
def _amount_tax(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id] = reduce( lambda x, y: x+y.amount, invoice.tax_line,0)
else:
res[invoice.id] = super(account_invoice, self)._amount_tax(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
def _amount_tax(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id] = reduce( lambda x, y: x+y.amount, invoice.tax_line,0)
else:
res[invoice.id] = super(account_invoice, self)._amount_tax(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
def _amount_total(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id]= invoice.amount_untaxed + invoice.amount_tax
else:
res[invoice.id] = super(account_invoice, self)._amount_total(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
def _amount_total(self, cr, uid, ids, name, args, context={}):
res = {}
for invoice in self.browse(cr,uid,ids):
if invoice.price_type == 'tax_included':
res[invoice.id]= invoice.amount_untaxed + invoice.amount_tax
else:
res[invoice.id] = super(account_invoice, self)._amount_total(cr, uid, [invoice.id], name, args, context)[invoice.id]
return res
_inherit = "account.invoice"
_columns = {
'price_type': fields.selection([('tax_included','Tax included'),
('tax_excluded','Tax excluded')],
'Price method', required=True, readonly=True,
states={'draft':[('readonly',False)]}),
'amount_untaxed': fields.function(_amount_untaxed, digits=(16,2), method=True,string='Untaxed Amount'),
'amount_tax': fields.function(_amount_tax, method=True, string='Tax', store=True),
'amount_total': fields.function(_amount_total, method=True, string='Total', store=True),
}
_defaults = {
'price_type': lambda *a: 'tax_excluded',
}
_inherit = "account.invoice"
_columns = {
'price_type': fields.selection([('tax_included','Tax included'),
('tax_excluded','Tax excluded')],
'Price method', required=True, readonly=True,
states={'draft':[('readonly',False)]}),
'amount_untaxed': fields.function(_amount_untaxed, digits=(16,2), method=True,string='Untaxed Amount'),
'amount_tax': fields.function(_amount_tax, method=True, string='Tax', store=True),
'amount_total': fields.function(_amount_total, method=True, string='Total', store=True),
}
_defaults = {
'price_type': lambda *a: 'tax_excluded',
}
account_invoice()
class account_invoice_line(osv.osv):
_inherit = "account.invoice.line"
def _amount_line(self, cr, uid, ids, name, args, context={}):
"""
Return the subtotal excluding taxes with respect to price_type.
"""
res = {}
tax_obj = self.pool.get('account.tax')
res = super(account_invoice_line, self)._amount_line(cr, uid, ids, name, args, context)
res2 = res.copy()
for line in self.browse(cr, uid, ids):
if not line.quantity:
res[line.id] = 0.0
continue
if line.invoice_id and line.invoice_id.price_type == 'tax_included':
product_taxes = None
if line.product_id:
if line.invoice_id.type in ('out_invoice', 'out_refund'):
product_taxes = line.product_id.taxes_id
else:
product_taxes = line.product_id.supplier_taxes_id
if product_taxes:
for tax in tax_obj.compute_inv(cr, uid, product_taxes, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] - round(tax['amount'], 2)
else:
for tax in tax_obj.compute_inv(cr, uid,line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] - round(tax['amount'], 2)
if name == 'price_subtotal_incl' and line.invoice_id and line.invoice_id.price_type == 'tax_included':
prod_taxe_ids = None
line_taxe_ids = None
if product_taxes:
prod_taxe_ids = [ t.id for t in product_taxes ]
prod_taxe_ids.sort()
line_taxe_ids = [ t.id for t in line.invoice_line_tax_id ]
line_taxe_ids.sort()
if product_taxes and prod_taxe_ids == line_taxe_ids:
res[line.id] = res2[line.id]
elif not line.product_id:
res[line.id] = res2[line.id]
else:
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] + tax['amount']
res[line.id]= round(res[line.id], 2)
return res
_inherit = "account.invoice.line"
def _amount_line(self, cr, uid, ids, name, args, context={}):
"""
Return the subtotal excluding taxes with respect to price_type.
"""
res = {}
tax_obj = self.pool.get('account.tax')
res = super(account_invoice_line, self)._amount_line(cr, uid, ids, name, args, context)
res2 = res.copy()
for line in self.browse(cr, uid, ids):
if not line.quantity:
res[line.id] = 0.0
continue
if line.invoice_id and line.invoice_id.price_type == 'tax_included':
product_taxes = None
if line.product_id:
if line.invoice_id.type in ('out_invoice', 'out_refund'):
product_taxes = line.product_id.taxes_id
else:
product_taxes = line.product_id.supplier_taxes_id
if product_taxes:
for tax in tax_obj.compute_inv(cr, uid, product_taxes, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] - round(tax['amount'], 2)
else:
for tax in tax_obj.compute_inv(cr, uid,line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] - round(tax['amount'], 2)
if name == 'price_subtotal_incl' and line.invoice_id and line.invoice_id.price_type == 'tax_included':
prod_taxe_ids = None
line_taxe_ids = None
if product_taxes:
prod_taxe_ids = [ t.id for t in product_taxes ]
prod_taxe_ids.sort()
line_taxe_ids = [ t.id for t in line.invoice_line_tax_id ]
line_taxe_ids.sort()
if product_taxes and prod_taxe_ids == line_taxe_ids:
res[line.id] = res2[line.id]
elif not line.product_id:
res[line.id] = res2[line.id]
else:
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
res[line.id] = res[line.id] + tax['amount']
res[line.id]= round(res[line.id], 2)
return res
def _price_unit_default(self, cr, uid, context={}):
if 'check_total' in context:
t = context['check_total']
if context.get('price_type', False) == 'tax_included':
for l in context.get('invoice_line', {}):
if len(l) >= 3 and l[2]:
p = l[2].get('price_unit', 0) * (1-l[2].get('discount', 0)/100.0)
t = t - (p * l[2].get('quantity'))
return t
return super(account_invoice_line, self)._price_unit_default(cr, uid, context)
return 0
def _price_unit_default(self, cr, uid, context={}):
if 'check_total' in context:
t = context['check_total']
if context.get('price_type', False) == 'tax_included':
for l in context.get('invoice_line', {}):
if len(l) >= 3 and l[2]:
p = l[2].get('price_unit', 0) * (1-l[2].get('discount', 0)/100.0)
t = t - (p * l[2].get('quantity'))
return t
return super(account_invoice_line, self)._price_unit_default(cr, uid, context)
return 0
_columns = {
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal w/o tax', store=True),
'price_subtotal_incl': fields.function(_amount_line, method=True, string='Subtotal'),
}
_columns = {
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal w/o tax', store=True),
'price_subtotal_incl': fields.function(_amount_line, method=True, string='Subtotal'),
}
_defaults = {
'price_unit': _price_unit_default,
}
_defaults = {
'price_unit': _price_unit_default,
}
def move_line_get_item(self, cr, uid, line, context={}):
return {
'type':'src',
'name':line.name,
'price_unit':line.price_subtotal / line.quantity,
'quantity':line.quantity,
'price':line.price_subtotal,
'account_id':line.account_id.id,
'product_id': line.product_id.id,
'uos_id':line.uos_id.id,
'account_analytic_id':line.account_analytic_id.id,
}
def move_line_get_item(self, cr, uid, line, context={}):
return {
'type':'src',
'name':line.name,
'price_unit':line.price_subtotal / line.quantity,
'quantity':line.quantity,
'price':line.price_subtotal,
'account_id':line.account_id.id,
'product_id': line.product_id.id,
'uos_id':line.uos_id.id,
'account_analytic_id':line.account_analytic_id.id,
}
def product_id_change_unit_price_inv(self, cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context={}):
if context.get('price_type', False) == 'tax_included':
return {'price_unit': price_unit,'invoice_line_tax_id': tax_id}
else:
return super(account_invoice_line, self).product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context)
def product_id_change_unit_price_inv(self, cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context={}):
if context.get('price_type', False) == 'tax_included':
return {'price_unit': price_unit,'invoice_line_tax_id': tax_id}
else:
return super(account_invoice_line, self).product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context)
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, price_type='tax_excluded', context={}):
context.update({'price_type': price_type})
return super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, price_unit, address_invoice_id, context=context)
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, price_type='tax_excluded', context={}):
context.update({'price_type': price_type})
return super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, price_unit, address_invoice_id, context=context)
account_invoice_line()
class account_invoice_tax(osv.osv):
_inherit = "account.invoice.tax"
_inherit = "account.invoice.tax"
def compute(self, cr, uid, invoice_id):
tax_grouped = {}
tax_obj = self.pool.get('account.tax')
cur_obj = self.pool.get('res.currency')
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
cur = inv.currency_id
def compute(self, cr, uid, invoice_id):
tax_grouped = {}
tax_obj = self.pool.get('account.tax')
cur_obj = self.pool.get('res.currency')
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
cur = inv.currency_id
if inv.price_type=='tax_excluded':
return super(account_invoice_tax,self).compute(cr, uid, invoice_id)
if inv.price_type=='tax_excluded':
return super(account_invoice_tax,self).compute(cr, uid, invoice_id)
for line in inv.invoice_line:
for tax in tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, (line.price_unit * (1-(line.discount or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id):
val={}
val['invoice_id'] = inv.id
val['name'] = tax['name']
val['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
val['manual'] = False
val['sequence'] = tax['sequence']
val['base'] = tax['price_unit'] * line['quantity']
for line in inv.invoice_line:
for tax in tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, (line.price_unit * (1-(line.discount or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id):
val={}
val['invoice_id'] = inv.id
val['name'] = tax['name']
val['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
val['manual'] = False
val['sequence'] = tax['sequence']
val['base'] = tax['price_unit'] * line['quantity']
if inv.type in ('out_invoice','in_invoice'):
val['base_code_id'] = tax['base_code_id']
val['tax_code_id'] = tax['tax_code_id']
val['base_amount'] = val['base'] * tax['base_sign']
val['tax_amount'] = val['amount'] * tax['tax_sign']
val['account_id'] = tax['account_collected_id'] or line.account_id.id
else:
val['base_code_id'] = tax['ref_base_code_id']
val['tax_code_id'] = tax['ref_tax_code_id']
val['base_amount'] = val['base'] * tax['ref_base_sign']
val['tax_amount'] = val['amount'] * tax['ref_tax_sign']
val['account_id'] = tax['account_paid_id'] or line.account_id.id
if inv.type in ('out_invoice','in_invoice'):
val['base_code_id'] = tax['base_code_id']
val['tax_code_id'] = tax['tax_code_id']
val['base_amount'] = val['base'] * tax['base_sign']
val['tax_amount'] = val['amount'] * tax['tax_sign']
val['account_id'] = tax['account_collected_id'] or line.account_id.id
else:
val['base_code_id'] = tax['ref_base_code_id']
val['tax_code_id'] = tax['ref_tax_code_id']
val['base_amount'] = val['base'] * tax['ref_base_sign']
val['tax_amount'] = val['amount'] * tax['ref_tax_sign']
val['account_id'] = tax['account_paid_id'] or line.account_id.id
key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
if not key in tax_grouped:
tax_grouped[key] = val
else:
tax_grouped[key]['amount'] += val['amount']
tax_grouped[key]['base'] += val['base']
tax_grouped[key]['base_amount'] += val['base_amount']
tax_grouped[key]['tax_amount'] += val['tax_amount']
key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
if not key in tax_grouped:
tax_grouped[key] = val
else:
tax_grouped[key]['amount'] += val['amount']
tax_grouped[key]['base'] += val['base']
tax_grouped[key]['base_amount'] += val['base_amount']
tax_grouped[key]['tax_amount'] += val['tax_amount']
return tax_grouped
return tax_grouped
account_invoice_tax()

View File

@ -26,17 +26,17 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "IBAN",
"version" : "1.0",
"author" : "Tiny",
"category" : "Generic Modules/Base",
"depends" : ["base"],
"description": """
"name" : "IBAN",
"version" : "1.0",
"author" : "Tiny",
"category" : "Generic Modules/Base",
"depends" : ["base"],
"description": """
This module install the base for IBAN bank accounts.
""",
"update_xml" : ["base_iban_view.xml"],
"init_xml" : ["base_iban_data.xml"],
"active": False,
"installable": True
""",
"update_xml" : ["base_iban_view.xml"],
"init_xml" : ["base_iban_data.xml"],
"active": False,
"installable": True
}

View File

@ -31,21 +31,21 @@ import netsvc
from osv import fields, osv
class res_partner_bank(osv.osv):
_inherit = "res.partner.bank"
_columns = {
'iban': fields.char('IBAN', size=34, readonly=True, help="International Bank Account Number"),
}
_inherit = "res.partner.bank"
_columns = {
'iban': fields.char('IBAN', size=34, readonly=True, help="International Bank Account Number"),
}
def name_get(self, cr, uid, ids, context=None):
res = []
to_check_ids = []
for id in self.browse(cr, uid, ids):
if id.state=='iban':
res.append((id.id,id.iban))
else:
to_check_ids.append(id.id)
res += super(res_partner_bank, self).name_get(cr, uid, to_check_ids, context)
return res
def name_get(self, cr, uid, ids, context=None):
res = []
to_check_ids = []
for id in self.browse(cr, uid, ids):
if id.state=='iban':
res.append((id.id,id.iban))
else:
to_check_ids.append(id.id)
res += super(res_partner_bank, self).name_get(cr, uid, to_check_ids, context)
return res
res_partner_bank()

View File

@ -26,12 +26,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Module publisher",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"category" : "Generic Modules/Base",
"description": """
"name" : "Module publisher",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"category" : "Generic Modules/Base",
"description": """
This module can be used by developpers to automatically publish their modules
in a few click to the following websites:
* http://TinyERP.com, section module
@ -41,10 +41,10 @@ in a few click to the following websites:
It adds a button "Publish module" on each module, so that you simply have
to call this button when you want to release a new version of your module.
""",
"depends" : ["base"],
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ "base_module_publish_wizard.xml" ],
"installable": True
""",
"depends" : ["base"],
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : [ "base_module_publish_wizard.xml" ],
"installable": True
}

View File

@ -39,13 +39,13 @@ import tools
intro_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="Publication information" colspan="4"/>
<field name="text" colspan="4" nolabel="1" width="300" height="200"/>
<separator string="Publication information" colspan="4"/>
<field name="text" colspan="4" nolabel="1" width="300" height="200"/>
</form>'''
intro_fields = {
'text': {'string':'Introduction', 'type':'text', 'readonly':True,
'default': lambda *args: """
'text': {'string':'Introduction', 'type':'text', 'readonly':True,
'default': lambda *args: """
This system will automatically publish the selected module to the
Tiny ERP official website. You can use it to quickly publish a new
module or update an existing one (new version).
@ -59,298 +59,298 @@ Thank you for contributing!
}
def _get_selection(self, cr, uid, datas, *args):
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php')
contents = a.read()
content = filter(None, contents.split('\n'))
result = map(lambda x:x.split('='), content)
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php')
contents = a.read()
content = filter(None, contents.split('\n'))
result = map(lambda x:x.split('='), content)
return result
return result
check_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="Verify your module information" colspan="4"/>
<notebook>
<page string="General">
<field name="name"/>
<field name="version"/>
<field name="author"/>
<field name="website" widget="url"/>
<field name="shortdesc"/>
<field name="operation"/>
<field name="category" colspan="4"/>
<newline/>
<field name="license"/>
<field name="include_src"/>
<newline/>
<field name="url_download" colspan="4" widget="url"/>
<field name="docurl" colspan="4" widget="url"/>
<field name="demourl" colspan="4" widget="url"/>
<field name="image"/>
</page>
<page string="Description">
<field name="description" colspan="4" nolabel="1"/>
</page>
</notebook>
<separator string="Verify your module information" colspan="4"/>
<notebook>
<page string="General">
<field name="name"/>
<field name="version"/>
<field name="author"/>
<field name="website" widget="url"/>
<field name="shortdesc"/>
<field name="operation"/>
<field name="category" colspan="4"/>
<newline/>
<field name="license"/>
<field name="include_src"/>
<newline/>
<field name="url_download" colspan="4" widget="url"/>
<field name="docurl" colspan="4" widget="url"/>
<field name="demourl" colspan="4" widget="url"/>
<field name="image"/>
</page>
<page string="Description">
<field name="description" colspan="4" nolabel="1"/>
</page>
</notebook>
</form>'''
check_fields = {
'name': {'string':'Name', 'type':'char', 'size':64, 'readonly':True},
'shortdesc': {'string':'Small description', 'type':'char', 'size':200,
'readonly':True},
'author': {'string':'Author', 'type':'char', 'size':128, 'readonly':True},
'website': {'string':'Website', 'type':'char', 'size':200, 'readonly':True},
'url': {'string':'Download URL', 'type':'char', 'size':200, 'readonly':True},
'image': {'string':'Image file', 'type':'image', 'help': 'support only .png files'},
'description': {'string':'Description', 'type':'text', 'readonly':True},
'version': {'string':'Version', 'type':'char', 'readonly':True},
'demourl': {'string':'Demo URL', 'type':'char', 'size':128,
'help': 'empty to keep existing value'},
'docurl': {'string':'Documentation URL', 'type':'char', 'size':128,
'help': 'Empty to keep existing value'},
'category': {'string':'Category', 'type':'selection', 'size':64, 'required':True,
'selection': _get_selection},
'license': {
'string':'Licence', 'type':'selection', 'size':64, 'required':True,
'selection': [('GPL-2', 'GPL-2'), ('Other proprietary','Other proprietary')],
'default': lambda *args: 'GPL-2'
},
'include_src': {'string': 'Include source', 'type': 'boolean',
'default': lambda *a: True},
'operation': {
'string':'Operation',
'type':'selection',
'readonly':True,
'selection':[('0','Creation'),('1','Modification')],
},
'url_download': {'string':'Download URL', 'type':'char', 'size':128,
'help': 'Keep empty for an auto upload of the module'},
'name': {'string':'Name', 'type':'char', 'size':64, 'readonly':True},
'shortdesc': {'string':'Small description', 'type':'char', 'size':200,
'readonly':True},
'author': {'string':'Author', 'type':'char', 'size':128, 'readonly':True},
'website': {'string':'Website', 'type':'char', 'size':200, 'readonly':True},
'url': {'string':'Download URL', 'type':'char', 'size':200, 'readonly':True},
'image': {'string':'Image file', 'type':'image', 'help': 'support only .png files'},
'description': {'string':'Description', 'type':'text', 'readonly':True},
'version': {'string':'Version', 'type':'char', 'readonly':True},
'demourl': {'string':'Demo URL', 'type':'char', 'size':128,
'help': 'empty to keep existing value'},
'docurl': {'string':'Documentation URL', 'type':'char', 'size':128,
'help': 'Empty to keep existing value'},
'category': {'string':'Category', 'type':'selection', 'size':64, 'required':True,
'selection': _get_selection},
'license': {
'string':'Licence', 'type':'selection', 'size':64, 'required':True,
'selection': [('GPL-2', 'GPL-2'), ('Other proprietary','Other proprietary')],
'default': lambda *args: 'GPL-2'
},
'include_src': {'string': 'Include source', 'type': 'boolean',
'default': lambda *a: True},
'operation': {
'string':'Operation',
'type':'selection',
'readonly':True,
'selection':[('0','Creation'),('1','Modification')],
},
'url_download': {'string':'Download URL', 'type':'char', 'size':128,
'help': 'Keep empty for an auto upload of the module'},
}
upload_info_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="User information" colspan="4"/>
<label string="Please provide here your login on the Tiny ERP website."
align="0.0" colspan="4"/>
<label string="If you don't have an access, you can create one http://www.openerp.com/"
align="0.0" colspan="4"/>
<field name="login"/>
<newline/>
<field name="password"/>
<newline/>
<field name="email"/>
<separator string="User information" colspan="4"/>
<label string="Please provide here your login on the Tiny ERP website."
align="0.0" colspan="4"/>
<label string="If you don't have an access, you can create one http://www.openerp.com/"
align="0.0" colspan="4"/>
<field name="login"/>
<newline/>
<field name="password"/>
<newline/>
<field name="email"/>
</form>'''
def _get_edit(self, cr, uid, datas, *args):
pool = pooler.get_pool(cr.dbname)
name = pool.get('ir.module.module').read(cr, uid, [datas['id']], ['name'])[0]['name']
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (name,))
content = a.read()
try:
email = self.pool.get('res.users').browse(cr, uid, uid).address.email or ''
except:
email =''
result = {'operation': ((content[0]=='0') and '0') or '1', 'email':email}
if (content[0]<>'0'):
result['category'] = content.split('\n')[1]
return result
pool = pooler.get_pool(cr.dbname)
name = pool.get('ir.module.module').read(cr, uid, [datas['id']], ['name'])[0]['name']
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (name,))
content = a.read()
try:
email = self.pool.get('res.users').browse(cr, uid, uid).address.email or ''
except:
email =''
result = {'operation': ((content[0]=='0') and '0') or '1', 'email':email}
if (content[0]<>'0'):
result['category'] = content.split('\n')[1]
return result
upload_info_fields = {
'login': {'string':'Login', 'type':'char', 'size':32, 'required':True},
'email': {'string':'Email', 'type':'char', 'size':100, 'required':True},
'password': {'string':'Password', 'type':'char', 'size':32, 'required':True,
'invisible':True},
'login': {'string':'Login', 'type':'char', 'size':32, 'required':True},
'email': {'string':'Email', 'type':'char', 'size':100, 'required':True},
'password': {'string':'Password', 'type':'char', 'size':32, 'required':True,
'invisible':True},
}
end_form = '''<?xml version="1.0"?>
<form string="Module publication">
<notebook>
<page string="Information">
<field name="text_end" colspan="4" nolabel="1" width="300" height="200"/>
</page>
<page string="Result">
<field name="result" colspan="4" nolabel="1"/>
</page>
</notebook>
<notebook>
<page string="Information">
<field name="text_end" colspan="4" nolabel="1" width="300" height="200"/>
</page>
<page string="Result">
<field name="result" colspan="4" nolabel="1"/>
</page>
</notebook>
</form>'''
end_fields = {
'text_end': {'string':'Summary', 'type':'text', 'readonly':True,
'default': lambda *args: """
'text_end': {'string':'Summary', 'type':'text', 'readonly':True,
'default': lambda *args: """
Thank you for contributing !
Your module has been successfully uploaded to the official website.
You must wait a few hours/days so that the Tiny ERP core team review
your module for approval on the website.
"""},
'result': {'string':'Result page', 'type':'text', 'readonly':True}
'result': {'string':'Result page', 'type':'text', 'readonly':True}
}
import httplib, mimetypes
def post_multipart(host, selector, fields, files):
def encode_multipart_formdata(fields, files):
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key,fname,value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"'
% (key, fname))
L.append('Content-Type: application/octet-stream')
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
content_type, body = encode_multipart_formdata(fields, files)
import httplib
def encode_multipart_formdata(fields, files):
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key,fname,value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"'
% (key, fname))
L.append('Content-Type: application/octet-stream')
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
content_type, body = encode_multipart_formdata(fields, files)
import httplib
headers = {"Content-type": content_type, "Accept": "*/*"}
conn = httplib.HTTPConnection(host)
conn.request("POST", selector, body, headers = headers)
response = conn.getresponse()
val = response.status
res = response.read()
conn.close()
return res
headers = {"Content-type": content_type, "Accept": "*/*"}
conn = httplib.HTTPConnection(host)
conn.request("POST", selector, body, headers = headers)
response = conn.getresponse()
val = response.status
res = response.read()
conn.close()
return res
def _upload(self, cr, uid, datas, context):
pool = pooler.get_pool(cr.dbname)
mod = pool.get('ir.module.module').browse(cr, uid, datas['id'])
download = datas['form']['url_download'] or ''
if not download:
res = module_zip.createzip(cr, uid, datas['id'], context,
b64enc=False, src=datas['form']['include_src'])
download = 'http://www.openerp.com/download/modules/'+res['module_filename']
result = post_multipart('www.openerp.com', '/mtree_upload.php',
[
('login',datas['form']['login']),
('password',datas['form']['password']),
('module_name',mod.name)
], [
('module', res['module_filename'], res['module_file'])
])
if result[0] == "1":
raise wizard.except_wizard(_('Error'), _('Login failed!'))
elif result[0] == "2":
raise wizard.except_wizard(_('Error'),
_('This version of the module is already exist on the server'))
elif result[0] != "0":
raise wizard.except_wizard(_('Error'), _('Failed to upload the file'))
pool = pooler.get_pool(cr.dbname)
mod = pool.get('ir.module.module').browse(cr, uid, datas['id'])
download = datas['form']['url_download'] or ''
if not download:
res = module_zip.createzip(cr, uid, datas['id'], context,
b64enc=False, src=datas['form']['include_src'])
download = 'http://www.openerp.com/download/modules/'+res['module_filename']
result = post_multipart('www.openerp.com', '/mtree_upload.php',
[
('login',datas['form']['login']),
('password',datas['form']['password']),
('module_name',mod.name)
], [
('module', res['module_filename'], res['module_file'])
])
if result[0] == "1":
raise wizard.except_wizard(_('Error'), _('Login failed!'))
elif result[0] == "2":
raise wizard.except_wizard(_('Error'),
_('This version of the module is already exist on the server'))
elif result[0] != "0":
raise wizard.except_wizard(_('Error'), _('Failed to upload the file'))
updata = {
'link_name': mod.shortdesc or '',
'new_cat_id': datas['form']['category'],
'link_desc': (mod.description or '').replace('\n','<br/>\n'),
'website': mod.website or '',
'price': '0.0',
'email': datas['form']['email'] or '',
'cust_1': download,
'cust_2': datas['form']['demourl'] or '', # Put here the download url
'cust_3': mod.url or '/',
'cust_4': datas['form']['docurl'] or '',
'cust_5': datas['form']['license'] or '',
'cust_6': mod.installed_version or '0',
'cust_7': mod.name,
'option': 'com_mtree',
'task': 'savelisting',
'Itemid': '99999999',
'cat_id': '0',
'adminForm': '',
'auto_login': datas['form']['login'],
'auto_password': datas['form']['password']
}
name = mod.name
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (name,))
aa = a.read()
if aa[0]<>'0':
updata['link_id']=aa.split('\n')[0]
updata['option'] = 'mtree'
updata = {
'link_name': mod.shortdesc or '',
'new_cat_id': datas['form']['category'],
'link_desc': (mod.description or '').replace('\n','<br/>\n'),
'website': mod.website or '',
'price': '0.0',
'email': datas['form']['email'] or '',
'cust_1': download,
'cust_2': datas['form']['demourl'] or '', # Put here the download url
'cust_3': mod.url or '/',
'cust_4': datas['form']['docurl'] or '',
'cust_5': datas['form']['license'] or '',
'cust_6': mod.installed_version or '0',
'cust_7': mod.name,
'option': 'com_mtree',
'task': 'savelisting',
'Itemid': '99999999',
'cat_id': '0',
'adminForm': '',
'auto_login': datas['form']['login'],
'auto_password': datas['form']['password']
}
name = mod.name
a = urllib.urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (name,))
aa = a.read()
if aa[0]<>'0':
updata['link_id']=aa.split('\n')[0]
updata['option'] = 'mtree'
files = []
if datas['form']['image']:
files.append(('link_image', 'link_image.png',
base64.decodestring(datas['form']['image'])))
result = post_multipart('www.openerp.com', '/index.php', updata.items(), files)
return {'result': result}
files = []
if datas['form']['image']:
files.append(('link_image', 'link_image.png',
base64.decodestring(datas['form']['image'])))
result = post_multipart('www.openerp.com', '/index.php', updata.items(), files)
return {'result': result}
def module_check(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
module = pool.get('ir.module.module').browse(cr, uid, data['id'], context)
if module.state != 'installed':
raise wizard.except_wizard(_('Error'), _('You could not publish a module that is not installed!'))
return {
'name': module.name,
'shortdesc': module.shortdesc,
'author': module.author,
'website': module.website,
'url': module.url,
'description': module.description,
'version': module.installed_version,
'license': module.license,
}
pool = pooler.get_pool(cr.dbname)
module = pool.get('ir.module.module').browse(cr, uid, data['id'], context)
if module.state != 'installed':
raise wizard.except_wizard(_('Error'), _('You could not publish a module that is not installed!'))
return {
'name': module.name,
'shortdesc': module.shortdesc,
'author': module.author,
'website': module.website,
'url': module.url,
'description': module.description,
'version': module.installed_version,
'license': module.license,
}
class base_module_publish(wizard.interface):
states = {
'init': {
'actions': [],
'result': {
'type':'form',
'arch':intro_form,
'fields':intro_fields,
'state':[
('end', 'Cancel', 'gtk-cancel'),
('step1', 'Continue', 'gtk-go-forward', True)
]
}
},
'step1': {
'actions': [module_check, _get_edit],
'result': {
'type':'form',
'arch':check_form,
'fields':check_fields,
'state':[
('end','Cancel', 'gtk-cancel'),
('init', 'Previous', 'gtk-go-back'),
('step2','Continue', 'gtk-go-forward', True)
]
}
},
'step2': {
'actions': [],
'result': {
'type':'form',
'arch':upload_info_form,
'fields':upload_info_fields,
'state':[
('end','Cancel', 'gtk-cancel'),
('step1', 'Previous', 'gtk-go-back'),
('publish','Publish', 'gtk-ok', True)
]
}
},
'publish': {
'actions': [_upload], # Action to develop: upload method
'result': {
'type':'form',
'arch':end_form,
'fields':end_fields,
'state':[
('end','Close', 'gtk-ok', True)
]
}
}
}
states = {
'init': {
'actions': [],
'result': {
'type':'form',
'arch':intro_form,
'fields':intro_fields,
'state':[
('end', 'Cancel', 'gtk-cancel'),
('step1', 'Continue', 'gtk-go-forward', True)
]
}
},
'step1': {
'actions': [module_check, _get_edit],
'result': {
'type':'form',
'arch':check_form,
'fields':check_fields,
'state':[
('end','Cancel', 'gtk-cancel'),
('init', 'Previous', 'gtk-go-back'),
('step2','Continue', 'gtk-go-forward', True)
]
}
},
'step2': {
'actions': [],
'result': {
'type':'form',
'arch':upload_info_form,
'fields':upload_info_fields,
'state':[
('end','Cancel', 'gtk-cancel'),
('step1', 'Previous', 'gtk-go-back'),
('publish','Publish', 'gtk-ok', True)
]
}
},
'publish': {
'actions': [_upload], # Action to develop: upload method
'result': {
'type':'form',
'arch':end_form,
'fields':end_fields,
'state':[
('end','Close', 'gtk-ok', True)
]
}
}
}
base_module_publish('base_module_publish.module_publish')

View File

@ -35,13 +35,13 @@ from urllib import urlopen
intro_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="Publication information" colspan="4"/>
<field name="text" colspan="4" nolabel="1"/>
<separator string="Publication information" colspan="4"/>
<field name="text" colspan="4" nolabel="1"/>
</form>'''
intro_fields = {
'text': {'string': 'Introduction', 'type': 'text', 'readonly': True,
'default': lambda *a: """
'text': {'string': 'Introduction', 'type': 'text', 'readonly': True,
'default': lambda *a: """
This system will automatically publish and upload the selected modules to the
Tiny ERP official website. You can use it to quickly update a set of
module (new version).
@ -56,129 +56,129 @@ Thanks you for contributing!
login_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="User information" colspan="4"/>
<label string="Please provide here your login on the Tiny ERP website."
align="0.0" colspan="4"/>
<label string="If you don't have an access, you can create one http://www.openerp.com/"
align="0.0" colspan="4"/>
<field name="login"/>
<newline/>
<field name="password"/>
<newline/>
<field name="email"/>
<separator string="User information" colspan="4"/>
<label string="Please provide here your login on the Tiny ERP website."
align="0.0" colspan="4"/>
<label string="If you don't have an access, you can create one http://www.openerp.com/"
align="0.0" colspan="4"/>
<field name="login"/>
<newline/>
<field name="password"/>
<newline/>
<field name="email"/>
</form>'''
login_fields = {
'login': {'string':'Login', 'type':'char', 'size':32, 'required':True},
'email': {'string':'Email', 'type':'char', 'size':100, 'required':True},
'password': {'string':'Password', 'type':'char', 'size':32, 'required':True,
'invisible':True},
'login': {'string':'Login', 'type':'char', 'size':32, 'required':True},
'email': {'string':'Email', 'type':'char', 'size':100, 'required':True},
'password': {'string':'Password', 'type':'char', 'size':32, 'required':True,
'invisible':True},
}
end_form = '''<?xml version="1.0"?>
<form string="Module publication">
<separator string="Upload information" colspan="4"/>
<field name="update" colspan="4"/>
<field name="already" colspan="4"/>
<field name="error" colspan="4"/>
<separator string="Upload information" colspan="4"/>
<field name="update" colspan="4"/>
<field name="already" colspan="4"/>
<field name="error" colspan="4"/>
</form>'''
end_fields= {
'update': {'type': 'text', 'string': 'Modules updated', 'readonly': True},
'already': {'type': 'text', 'string': 'Modules already updated',
'readonly': True},
'error': {'type': 'text', 'string': 'Modules in error', 'readonly': True},
'update': {'type': 'text', 'string': 'Modules updated', 'readonly': True},
'already': {'type': 'text', 'string': 'Modules already updated',
'readonly': True},
'error': {'type': 'text', 'string': 'Modules in error', 'readonly': True},
}
def _upload(self, cr, uid, datas, context):
pool = pooler.get_pool(cr.dbname)
modules = pool.get('ir.module.module').browse(cr, uid, datas['ids'])
log = [[], [], []] # [update, already, error]
for mod in modules: # whoooouuuuffff update
if mod.state != 'installed':
result[2].append(mod.name)
continue
res = module_zip.createzip(cr, uid, mod.id, context, b64enc=False,
src=(mod.license in ('GPL-2')))
download = 'http://www.openerp.com/download/modules/'+res['module_filename']
result = post_multipart('www.openerp.com', '/mtree_upload.php',
[('login', datas['form']['login']),
('password', datas['form']['password']),
('module_name', mod.name)
], [('module', res['module_filename'],
res['module_file'])
])
if result[0] == "1":
raise wizard.except_wizard('Error', 'Login failed!')
elif result[0] == "0":
log[0].append(mod.name)
elif result[0] == "2":
log[1].append(mod.name)
else:
log[2].append(mod.name)
updata = {
'link_name': mod.shortdesc or '',
'link_desc': (mod.description or '').replace('\n','<br/>\n'),
'website': mod.website or '',
'email': datas['form']['email'] or '',
'cust_1': download,
'cust_3': mod.url or '/',
'cust_6': mod.installed_version or '0',
'cust_7': mod.name,
'option': 'com_mtree',
'task': 'savelisting',
'Itemid': '99999999',
'cat_id': '0',
'adminForm': '',
'auto_login': datas['form']['login'],
'auto_password': datas['form']['password']
}
a = urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (mod.name,))
aa = a.read()
if aa[0]<>'0':
updata['link_id']=aa.split('\n')[0]
updata['cat_id']=aa.split('\n')[1]
updata['option'] = 'mtree'
result = post_multipart('www.openerp.com', '/index.php', updata.items(), [])
return {'update': '\n'.join(log[0]), 'already': '\n'.join(log[1]),
'error': '\n'.join(log[2])}
pool = pooler.get_pool(cr.dbname)
modules = pool.get('ir.module.module').browse(cr, uid, datas['ids'])
log = [[], [], []] # [update, already, error]
for mod in modules: # whoooouuuuffff update
if mod.state != 'installed':
result[2].append(mod.name)
continue
res = module_zip.createzip(cr, uid, mod.id, context, b64enc=False,
src=(mod.license in ('GPL-2')))
download = 'http://www.openerp.com/download/modules/'+res['module_filename']
result = post_multipart('www.openerp.com', '/mtree_upload.php',
[('login', datas['form']['login']),
('password', datas['form']['password']),
('module_name', mod.name)
], [('module', res['module_filename'],
res['module_file'])
])
if result[0] == "1":
raise wizard.except_wizard('Error', 'Login failed!')
elif result[0] == "0":
log[0].append(mod.name)
elif result[0] == "2":
log[1].append(mod.name)
else:
log[2].append(mod.name)
updata = {
'link_name': mod.shortdesc or '',
'link_desc': (mod.description or '').replace('\n','<br/>\n'),
'website': mod.website or '',
'email': datas['form']['email'] or '',
'cust_1': download,
'cust_3': mod.url or '/',
'cust_6': mod.installed_version or '0',
'cust_7': mod.name,
'option': 'com_mtree',
'task': 'savelisting',
'Itemid': '99999999',
'cat_id': '0',
'adminForm': '',
'auto_login': datas['form']['login'],
'auto_password': datas['form']['password']
}
a = urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (mod.name,))
aa = a.read()
if aa[0]<>'0':
updata['link_id']=aa.split('\n')[0]
updata['cat_id']=aa.split('\n')[1]
updata['option'] = 'mtree'
result = post_multipart('www.openerp.com', '/index.php', updata.items(), [])
return {'update': '\n'.join(log[0]), 'already': '\n'.join(log[1]),
'error': '\n'.join(log[2])}
class base_module_publish_all(wizard.interface):
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': intro_form,
'fields': intro_fields,
'state': [
('end', 'Cancel'),
('login', 'Ok'),
]
}
},
'login': {
'actions': [],
'result': {
'type': 'form',
'arch': login_form,
'fields': login_fields,
'state': [
('end', 'Cancel'),
('publish', 'Publish')
]
}
},
'publish': {
'actions': [_upload],
'result': {
'type': 'form',
'arch': end_form,
'fields': end_fields,
'state': [
('end', 'Close')
]
}
},
}
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': intro_form,
'fields': intro_fields,
'state': [
('end', 'Cancel'),
('login', 'Ok'),
]
}
},
'login': {
'actions': [],
'result': {
'type': 'form',
'arch': login_form,
'fields': login_fields,
'state': [
('end', 'Cancel'),
('publish', 'Publish')
]
}
},
'publish': {
'actions': [_upload],
'result': {
'type': 'form',
'arch': end_form,
'fields': end_fields,
'state': [
('end', 'Close')
]
}
},
}
base_module_publish_all('base_module_publish.module_publish_all')

View File

@ -36,46 +36,46 @@ import StringIO
import base64
def _zippy(archive, fromurl, path, src=True):
url = os.path.join(fromurl, path)
if os.path.isdir(url):
if path.split('/')[-1].startswith('.'):
return False
for fname in os.listdir(url):
_zippy(archive, fromurl, path and os.path.join(path, fname) or fname, src=src)
else:
if src:
exclude = ['pyo', 'pyc']
else:
exclude = ['py','pyo','pyc']
if (path.split('.')[-1] not in exclude) or (os.path.basename(path)=='__terp__.py'):
archive.write(os.path.join(fromurl, path), path)
return True
url = os.path.join(fromurl, path)
if os.path.isdir(url):
if path.split('/')[-1].startswith('.'):
return False
for fname in os.listdir(url):
_zippy(archive, fromurl, path and os.path.join(path, fname) or fname, src=src)
else:
if src:
exclude = ['pyo', 'pyc']
else:
exclude = ['py','pyo','pyc']
if (path.split('.')[-1] not in exclude) or (os.path.basename(path)=='__terp__.py'):
archive.write(os.path.join(fromurl, path), path)
return True
def createzip(cr, uid, moduleid, context, b64enc=True, src=True):
pool = pooler.get_pool(cr.dbname)
module_obj = pool.get('ir.module.module')
pool = pooler.get_pool(cr.dbname)
module_obj = pool.get('ir.module.module')
module = module_obj.browse(cr, uid, moduleid)
module = module_obj.browse(cr, uid, moduleid)
if module.state != 'installed':
raise wizard.except_wizard(_('Error'),
_('Can not export module that is not installed!'))
if module.state != 'installed':
raise wizard.except_wizard(_('Error'),
_('Can not export module that is not installed!'))
ad = tools.config['addons_path']
if os.path.isdir(os.path.join(ad, module.name)):
archname = StringIO.StringIO('wb')
archive = PyZipFile(archname, "w", ZIP_DEFLATED)
archive.writepy(os.path.join(ad, module.name))
_zippy(archive, ad, module.name, src=src)
archive.close()
val =archname.getvalue()
archname.close()
elif os.path.isfile(os.path.join(ad, module.name + '.zip')):
val = file(os.path.join(ad, module.name + '.zip'), 'rb').read()
else:
raise wizard.except_wizard(_('Error'), _('Could not find the module to export!'))
if b64enc:
val =base64.encodestring(val)
return {'module_file':val, 'module_filename': module.name + '-' + \
(module.installed_version or '0') + '.zip'}
ad = tools.config['addons_path']
if os.path.isdir(os.path.join(ad, module.name)):
archname = StringIO.StringIO('wb')
archive = PyZipFile(archname, "w", ZIP_DEFLATED)
archive.writepy(os.path.join(ad, module.name))
_zippy(archive, ad, module.name, src=src)
archive.close()
val =archname.getvalue()
archname.close()
elif os.path.isfile(os.path.join(ad, module.name + '.zip')):
val = file(os.path.join(ad, module.name + '.zip'), 'rb').read()
else:
raise wizard.except_wizard(_('Error'), _('Could not find the module to export!'))
if b64enc:
val =base64.encodestring(val)
return {'module_file':val, 'module_filename': module.name + '-' + \
(module.installed_version or '0') + '.zip'}

View File

@ -35,42 +35,42 @@ import module_zip
init_form = '''<?xml version="1.0"?>
<form string="Export module">
<separator string="Export module" colspan="4"/>
<field name="include_src"/>
<separator string="Export module" colspan="4"/>
<field name="include_src"/>
</form>'''
init_fields = {
'include_src': {'string': 'Include sources', 'type': 'boolean',
'default': lambda *a: True,},
'include_src': {'string': 'Include sources', 'type': 'boolean',
'default': lambda *a: True,},
}
finish_form = '''<?xml version="1.0"?>
<form string="Finish">
<separator string="Module successfully exported !" colspan="4"/>
<field name="module_file"/>
<newline/>
<field name="module_filename"/>
<separator string="Module successfully exported !" colspan="4"/>
<field name="module_file"/>
<newline/>
<field name="module_filename"/>
</form>'''
finish_fields = {
'module_file': {'string': 'Module .zip file', 'type':'binary', 'readonly':True},
'module_filename': {'string': 'Filename', 'type':'char', 'size': 64, 'readonly':True},
'module_file': {'string': 'Module .zip file', 'type':'binary', 'readonly':True},
'module_filename': {'string': 'Filename', 'type':'char', 'size': 64, 'readonly':True},
}
class move_module_wizard(wizard.interface):
def createzip(self, cr, uid, data, context):
return module_zip.createzip(cr, uid, data['id'], context, src=data['form']['include_src'])
def createzip(self, cr, uid, data, context):
return module_zip.createzip(cr, uid, data['id'], context, src=data['form']['include_src'])
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': init_form,
'fields': init_fields, 'state': [('end', 'Cancel'), ('zip', 'Ok')]},
},
'zip': {
'actions': [createzip],
'result': {'type': 'form', 'arch': finish_form,
'fields': finish_fields, 'state': [('end', 'Close')]},
}
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': init_form,
'fields': init_fields, 'state': [('end', 'Cancel'), ('zip', 'Ok')]},
},
'zip': {
'actions': [createzip],
'result': {'type': 'form', 'arch': finish_form,
'fields': finish_fields, 'state': [('end', 'Close')]},
}
}
move_module_wizard('base_module_publish.module_export')

View File

@ -26,34 +26,34 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Base Setup",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"category" : "Generic Modules/Base",
"description": """
This module implements a configuration system that helps user
to configure the system at the installation of a new database.
"name" : "Base Setup",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"category" : "Generic Modules/Base",
"description": """
This module implements a configuration system that helps user
to configure the system at the installation of a new database.
It allows you to select between a list of profiles to install:
* Minimal profile
* Accounting only
* Services companies
* Manufacturing companies
It allows you to select between a list of profiles to install:
* Minimal profile
* Accounting only
* Services companies
* Manufacturing companies
It also asks screens to help easily configure your company, the header and
footer, the account chart to install and the language.
""",
"depends" : ["base"],
"init_xml" : [
"base_setup_data.xml",
],
"demo_xml" : [
"base_setup_demo.xml",
],
"update_xml" : [
"base_setup_wizard.xml",
],
"active": True,
"installable": True
It also asks screens to help easily configure your company, the header and
footer, the account chart to install and the language.
""",
"depends" : ["base"],
"init_xml" : [
"base_setup_data.xml",
],
"demo_xml" : [
"base_setup_demo.xml",
],
"update_xml" : [
"base_setup_wizard.xml",
],
"active": True,
"installable": True
}

View File

@ -30,8 +30,8 @@
from osv import fields, osv
class base_setup(osv.osv):
_name="base_setup.base_setup"
_columns={
'name': fields.char("Name", size=128),
}
_name="base_setup.base_setup"
_columns={
'name': fields.char("Name", size=128),
}
base_setup()

View File

@ -35,418 +35,418 @@ import os
view_form_profit = """<?xml version="1.0"?>
<form string="Setup">
<image name="gtk-dialog-info"/>
<group>
<separator string="Select a profile" colspan="2"/>
<newline/>
<field align="0.0" name="profile"/>
<newline/>
<label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
<newline/>
<label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
</group>
<image name="gtk-dialog-info"/>
<group>
<separator string="Select a profile" colspan="2"/>
<newline/>
<field align="0.0" name="profile"/>
<newline/>
<label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
<newline/>
<label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
</group>
</form>"""
view_form_charts = """<?xml version="1.0"?>
<form string="Setup">
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Select a chart of accounts" colspan="2"/>
<newline/>
<field name="charts" align="0.0"/>
<newline/>
<label string="There are many other chart of accounts available on the OpenERP website." colspan="2" align="0.0"/>
<newline/>
<label string="If you don't select one now, you'll be able to install an other one through the Administration menu." colspan="2" align="0.0"/>
</group>
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Select a chart of accounts" colspan="2"/>
<newline/>
<field name="charts" align="0.0"/>
<newline/>
<label string="There are many other chart of accounts available on the OpenERP website." colspan="2" align="0.0"/>
<newline/>
<label string="If you don't select one now, you'll be able to install an other one through the Administration menu." colspan="2" align="0.0"/>
</group>
</form>"""
view_form_company = """<?xml version="1.0"?>
<form string="Setup">
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Define main company" colspan="4"/>
<newline/>
<field name="name" align="0.0" colspan="4" required="True"/>
<newline/>
<field name="street" align="0.0"/>
<field name="street2" align="0.0"/>
<field name="zip" align="0.0"/>
<field name="city" align="0.0"/>
<field name="country_id" align="0.0"/>
<field name="state_id" align="0.0"/>
<field name="email" align="0.0"/>
<field name="phone" align="0.0"/>
<field name="currency" align="0.0"/>
<separator string="Report header" colspan="4"/>
<newline/>
<field name="rml_header1" align="0.0" colspan="4"/>
<field name="rml_footer1" align="0.0" colspan="4"/>
<field name="rml_footer2" align="0.0" colspan="4"/>
</group>
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Define main company" colspan="4"/>
<newline/>
<field name="name" align="0.0" colspan="4" required="True"/>
<newline/>
<field name="street" align="0.0"/>
<field name="street2" align="0.0"/>
<field name="zip" align="0.0"/>
<field name="city" align="0.0"/>
<field name="country_id" align="0.0"/>
<field name="state_id" align="0.0"/>
<field name="email" align="0.0"/>
<field name="phone" align="0.0"/>
<field name="currency" align="0.0"/>
<separator string="Report header" colspan="4"/>
<newline/>
<field name="rml_header1" align="0.0" colspan="4"/>
<field name="rml_footer1" align="0.0" colspan="4"/>
<field name="rml_footer2" align="0.0" colspan="4"/>
</group>
</form>"""
view_form_update = """<?xml version="1.0"?>
<form string="Setup">
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Summary" colspan="2"/>
<newline/>
<field name="profile" align="0.0" readonly="1"/>
<newline/>
<field name="charts" align="0.0" readonly="1"/>
<newline/>
<field name="name" align="0.0" readonly="1"/>
</group>
<image name="gtk-dialog-info" colspan="2"/>
<group>
<separator string="Summary" colspan="2"/>
<newline/>
<field name="profile" align="0.0" readonly="1"/>
<newline/>
<field name="charts" align="0.0" readonly="1"/>
<newline/>
<field name="name" align="0.0" readonly="1"/>
</group>
</form>
"""
view_form_finish = """<?xml version="1.0"?>
<form string="Setup">
<image name="gtk-dialog-info" colspan="2"/>
<group colspan="2" col="4">
<separator colspan="4" string="Installation Done"/>
<label align="0.0" colspan="4" string="Your new database is now fully installed."/>
<label align="0.0" colspan="4" string="You can start configuring the system or connect directly to the database using the default setup."/>
</group>
<image name="gtk-dialog-info" colspan="2"/>
<group colspan="2" col="4">
<separator colspan="4" string="Installation Done"/>
<label align="0.0" colspan="4" string="Your new database is now fully installed."/>
<label align="0.0" colspan="4" string="You can start configuring the system or connect directly to the database using the default setup."/>
</group>
</form>
"""
class wizard_base_setup(wizard.interface):
def _get_profiles(self, cr, uid, context):
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'),
('state', '<>', 'uninstallable')])
res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
res.append((-1, 'Minimal Profile'))
res.sort()
return res
def _get_profiles(self, cr, uid, context):
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'),
('state', '<>', 'uninstallable')])
res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
res.append((-1, 'Minimal Profile'))
res.sort()
return res
def _get_charts(self, cr, uid, context):
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'),
('state', '<>', 'uninstallable')])
res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
res.append((-1, 'None'))
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _get_charts(self, cr, uid, context):
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'),
('state', '<>', 'uninstallable')])
res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
res.append((-1, 'None'))
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _get_company(self, cr, uid, data, context):
pool=pooler.get_pool(cr.dbname)
company_obj=pool.get('res.company')
ids=company_obj.search(cr, uid, [])
if not ids:
return {}
company=company_obj.browse(cr, uid, ids)[0]
self.fields['name']['default']=company.name
self.fields['currency']['default']=company.currency_id.id
return {}
#self.fields['rml_header1']['default']=company.rml_header1
#self.fields['rml_footer1']['default']=company.rml_footer1
#self.fields['rml_footer2']['default']=company.rml_footer2
#if not company.partner_id.address:
# return {}
#address=company.partner_id.address[0]
#self.fields['street']['default']=address.street
#self.fields['street2']['default']=address.street2
#self.fields['zip']['default']=address.zip
#self.fields['city']['default']=address.city
#self.fields['email']['default']=address.email
#self.fields['phone']['default']=address.phone
#if address.state_id:
# self.fields['state_id']['default']=address.state_id.id
#else:
# self.fields['state_id']['default']=-1
#if address.country_id:
# self.fields['country_id']['default']=address.country_id.id
#else:
# self.fields['country_id']['default']=-1
#return {}
def _get_company(self, cr, uid, data, context):
pool=pooler.get_pool(cr.dbname)
company_obj=pool.get('res.company')
ids=company_obj.search(cr, uid, [])
if not ids:
return {}
company=company_obj.browse(cr, uid, ids)[0]
self.fields['name']['default']=company.name
self.fields['currency']['default']=company.currency_id.id
return {}
#self.fields['rml_header1']['default']=company.rml_header1
#self.fields['rml_footer1']['default']=company.rml_footer1
#self.fields['rml_footer2']['default']=company.rml_footer2
#if not company.partner_id.address:
# return {}
#address=company.partner_id.address[0]
#self.fields['street']['default']=address.street
#self.fields['street2']['default']=address.street2
#self.fields['zip']['default']=address.zip
#self.fields['city']['default']=address.city
#self.fields['email']['default']=address.email
#self.fields['phone']['default']=address.phone
#if address.state_id:
# self.fields['state_id']['default']=address.state_id.id
#else:
# self.fields['state_id']['default']=-1
#if address.country_id:
# self.fields['country_id']['default']=address.country_id.id
#else:
# self.fields['country_id']['default']=-1
#return {}
def _get_states(self, cr, uid, context):
pool=pooler.get_pool(cr.dbname)
state_obj=pool.get('res.country.state')
ids=state_obj.search(cr, uid, [])
res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
res.append((-1, ''))
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _get_states(self, cr, uid, context):
pool=pooler.get_pool(cr.dbname)
state_obj=pool.get('res.country.state')
ids=state_obj.search(cr, uid, [])
res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
res.append((-1, ''))
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _get_countries(self, cr, uid, context):
pool=pooler.get_pool(cr.dbname)
country_obj=pool.get('res.country')
ids=country_obj.search(cr, uid, [])
res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _get_countries(self, cr, uid, context):
pool=pooler.get_pool(cr.dbname)
country_obj=pool.get('res.country')
ids=country_obj.search(cr, uid, [])
res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
res.sort(lambda x,y: cmp(x[1],y[1]))
return res
def _update(self, cr, uid, data, context):
pool=pooler.get_pool(cr.dbname)
form=data['form']
if 'profile' in data['form'] and data['form']['profile'] > 0:
module_obj=pool.get('ir.module.module')
module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
if 'charts' in data['form'] and data['form']['charts'] > 0:
module_obj=pool.get('ir.module.module')
module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
def _update(self, cr, uid, data, context):
pool=pooler.get_pool(cr.dbname)
form=data['form']
if 'profile' in data['form'] and data['form']['profile'] > 0:
module_obj=pool.get('ir.module.module')
module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
if 'charts' in data['form'] and data['form']['charts'] > 0:
module_obj=pool.get('ir.module.module')
module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
company_obj=pool.get('res.company')
partner_obj=pool.get('res.partner')
address_obj=pool.get('res.partner.address')
ids=company_obj.search(cr, uid, [])
company=company_obj.browse(cr, uid, ids)[0]
company_obj.write(cr, uid, [company.id], {
'name': form['name'],
'rml_header1': form['rml_header1'],
'rml_footer1': form['rml_footer1'],
'rml_footer2': form['rml_footer2'],
'currency_id': form['currency'],
})
partner_obj.write(cr, uid, [company.partner_id.id], {
'name': form['name'],
})
values={
'name': form['name'],
'street': form['street'],
'street2': form['street2'],
'zip': form['zip'],
'city': form['city'],
'email': form['email'],
'phone': form['phone'],
'country_id': form['country_id'],
}
if form['state_id'] > 0:
values['state_id']=form['state_id']
if company.partner_id.address:
address=company.partner_id.address[0]
address_obj.write(cr, uid, [address.id], values)
else:
values['partner_id']=company.partner_id.id
add_id=address_obj.create(cr, uid, values)
company_obj=pool.get('res.company')
partner_obj=pool.get('res.partner')
address_obj=pool.get('res.partner.address')
ids=company_obj.search(cr, uid, [])
company=company_obj.browse(cr, uid, ids)[0]
company_obj.write(cr, uid, [company.id], {
'name': form['name'],
'rml_header1': form['rml_header1'],
'rml_footer1': form['rml_footer1'],
'rml_footer2': form['rml_footer2'],
'currency_id': form['currency'],
})
partner_obj.write(cr, uid, [company.partner_id.id], {
'name': form['name'],
})
values={
'name': form['name'],
'street': form['street'],
'street2': form['street2'],
'zip': form['zip'],
'city': form['city'],
'email': form['email'],
'phone': form['phone'],
'country_id': form['country_id'],
}
if form['state_id'] > 0:
values['state_id']=form['state_id']
if company.partner_id.address:
address=company.partner_id.address[0]
address_obj.write(cr, uid, [address.id], values)
else:
values['partner_id']=company.partner_id.id
add_id=address_obj.create(cr, uid, values)
cr.commit()
(db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
cr.commit()
(db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
lang_obj=pool.get('res.lang')
lang_ids=lang_obj.search(cr, uid, [])
langs=lang_obj.browse(cr, uid, lang_ids)
for lang in langs:
if lang.code and lang.code != 'en_US':
filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
tools.trans_load(cr.dbname, filename, lang.code)
return {}
lang_obj=pool.get('res.lang')
lang_ids=lang_obj.search(cr, uid, [])
langs=lang_obj.browse(cr, uid, lang_ids)
for lang in langs:
if lang.code and lang.code != 'en_US':
filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
tools.trans_load(cr.dbname, filename, lang.code)
return {}
def _menu(self, cr, uid, data, context):
users_obj=pooler.get_pool(cr.dbname).get('res.users')
action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
def _menu(self, cr, uid, data, context):
users_obj=pooler.get_pool(cr.dbname).get('res.users')
action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
menu=action_obj.browse(cr, uid, ids)[0]
ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
menu=action_obj.browse(cr, uid, ids)[0]
ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'action_id': menu.id})
ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'menu_id': menu.id})
ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'action_id': menu.id})
ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'menu_id': menu.id})
return {
'name': menu.name,
'type': menu.type,
'view_id': (menu.view_id and\
(menu.view_id.id, menu.view_id.name)) or False,
'domain': menu.domain,
'res_model': menu.res_model,
'src_model': menu.src_model,
'view_type': menu.view_type,
'view_mode': menu.view_mode,
'views': menu.views,
}
return {
'name': menu.name,
'type': menu.type,
'view_id': (menu.view_id and\
(menu.view_id.id, menu.view_id.name)) or False,
'domain': menu.domain,
'res_model': menu.res_model,
'src_model': menu.src_model,
'view_type': menu.view_type,
'view_mode': menu.view_mode,
'views': menu.views,
}
def _next(self, cr, uid, data, context):
if not data['form']['profile'] or data['form']['profile'] <= 0:
return 'company'
return 'charts'
def _next(self, cr, uid, data, context):
if not data['form']['profile'] or data['form']['profile'] <= 0:
return 'company'
return 'charts'
def _previous(self, cr, uid, data, context):
if 'profile' not in data['form'] or data['form']['profile'] <= 0:
return 'init'
return 'charts'
def _previous(self, cr, uid, data, context):
if 'profile' not in data['form'] or data['form']['profile'] <= 0:
return 'init'
return 'charts'
def _config(self, cr, uid, data, context=None):
users_obj=pooler.get_pool(cr.dbname).get('res.users')
action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
def _config(self, cr, uid, data, context=None):
users_obj=pooler.get_pool(cr.dbname).get('res.users')
action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
menu=action_obj.browse(cr, uid, ids)[0]
ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
menu=action_obj.browse(cr, uid, ids)[0]
ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'action_id': menu.id})
ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'menu_id': menu.id})
return {
ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'action_id': menu.id})
ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
users_obj.write(cr, uid, ids, {'menu_id': menu.id})
return {
'view_type': 'form',
"view_mode": 'form',
'res_model': 'ir.module.module.configuration.wizard',
'type': 'ir.actions.act_window',
'target':'new',
'res_model': 'ir.module.module.configuration.wizard',
'type': 'ir.actions.act_window',
'target':'new',
}
fields={
'profile':{
'string':'Profile',
'type':'selection',
'selection':_get_profiles,
'default': -1,
'required': True,
},
'charts':{
'string':'Chart of accounts',
'type':'selection',
'selection':_get_charts,
'default': -1,
'required': True,
},
'name':{
'string': 'Company Name',
'type': 'char',
'size': 64,
},
'street':{
'string': 'Street',
'type': 'char',
'size': 128,
},
'street2':{
'string': 'Street2',
'type': 'char',
'size': 128,
},
'zip':{
'string': 'Zip code',
'type': 'char',
'size': 24,
},
'city':{
'string': 'City',
'type': 'char',
'size': 128,
},
'state_id':{
'string': 'State',
'type': 'selection',
'selection':_get_states,
},
'country_id':{
'string': 'Country',
'type': 'selection',
'selection':_get_countries,
},
'email':{
'string': 'E-mail',
'type': 'char',
'size': 64,
},
'phone':{
'string': 'Phone',
'type': 'char',
'size': 64,
},
'currency': {
'string': 'Currency',
'type': 'many2one',
'relation': 'res.currency',
'required': True,
},
'rml_header1':{
'string': 'Report Header',
'type': 'char',
'help': """This sentence will appear at the top right corner of your reports.
fields={
'profile':{
'string':'Profile',
'type':'selection',
'selection':_get_profiles,
'default': -1,
'required': True,
},
'charts':{
'string':'Chart of accounts',
'type':'selection',
'selection':_get_charts,
'default': -1,
'required': True,
},
'name':{
'string': 'Company Name',
'type': 'char',
'size': 64,
},
'street':{
'string': 'Street',
'type': 'char',
'size': 128,
},
'street2':{
'string': 'Street2',
'type': 'char',
'size': 128,
},
'zip':{
'string': 'Zip code',
'type': 'char',
'size': 24,
},
'city':{
'string': 'City',
'type': 'char',
'size': 128,
},
'state_id':{
'string': 'State',
'type': 'selection',
'selection':_get_states,
},
'country_id':{
'string': 'Country',
'type': 'selection',
'selection':_get_countries,
},
'email':{
'string': 'E-mail',
'type': 'char',
'size': 64,
},
'phone':{
'string': 'Phone',
'type': 'char',
'size': 64,
},
'currency': {
'string': 'Currency',
'type': 'many2one',
'relation': 'res.currency',
'required': True,
},
'rml_header1':{
'string': 'Report Header',
'type': 'char',
'help': """This sentence will appear at the top right corner of your reports.
We suggest you to put a slogan here:
"Open Source Business Solutions".""",
'size': 200,
},
'rml_footer1':{
'string': 'Report Footer 1',
'type': 'char',
'help': """This sentence will appear at the bottom of your reports.
'size': 200,
},
'rml_footer1':{
'string': 'Report Footer 1',
'type': 'char',
'help': """This sentence will appear at the bottom of your reports.
We suggest you to write legal sentences here:
Web: http://openerp.com - Fax: +32.81.73.35.01 - Fortis Bank: 126-2013269-07""",
'size': 200,
},
'rml_footer2':{
'string': 'Report Footer 2',
'help': """This sentence will appear at the bottom of your reports.
'size': 200,
},
'rml_footer2':{
'string': 'Report Footer 2',
'help': """This sentence will appear at the bottom of your reports.
We suggest you to put bank information here:
IBAN: BE74 1262 0121 6907 - SWIFT: CPDF BE71 - VAT: BE0477.472.701""",
'type': 'char',
'size': 200,
},
}
states={
'init':{
'actions': [_get_company],
'result': {'type': 'form', 'arch': view_form_profit, 'fields': fields,
'state': [
('menu', 'Cancel', 'gtk-cancel'),
('next', 'Next', 'gtk-go-forward', True)
]
}
},
'next': {
'actions': [],
'result': {'type': 'choice', 'next_state': _next}
},
'charts':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_charts, 'fields': fields,
'state':[
('init', 'Previous', 'gtk-go-back'),
('company', 'Next', 'gtk-go-forward', True)
]
}
},
'company':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_company, 'fields': fields,
'state': [
('previous', 'Previous', 'gtk-go-back'),
('update', 'Next', 'gtk-go-forward', True)
]
}
},
'previous':{
'actions': [],
'result': {'type': 'choice', 'next_state': _previous}
},
'update':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_update, 'fields': fields,
'state': [
('company', 'Previous', 'gtk-go-back'),
('finish', 'Install', 'gtk-ok', True)
]
}
},
'finish':{
'actions': [_update],
'result': {'type': 'form', 'arch': view_form_finish, 'fields': {},
'state': [
('menu', 'Use Directly'),
('config', 'Start Configuration', 'gtk-ok', True)
]
}
},
'config': {
'type': 'char',
'size': 200,
},
}
states={
'init':{
'actions': [_get_company],
'result': {'type': 'form', 'arch': view_form_profit, 'fields': fields,
'state': [
('menu', 'Cancel', 'gtk-cancel'),
('next', 'Next', 'gtk-go-forward', True)
]
}
},
'next': {
'actions': [],
'result': {'type': 'choice', 'next_state': _next}
},
'charts':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_charts, 'fields': fields,
'state':[
('init', 'Previous', 'gtk-go-back'),
('company', 'Next', 'gtk-go-forward', True)
]
}
},
'company':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_company, 'fields': fields,
'state': [
('previous', 'Previous', 'gtk-go-back'),
('update', 'Next', 'gtk-go-forward', True)
]
}
},
'previous':{
'actions': [],
'result': {'type': 'choice', 'next_state': _previous}
},
'update':{
'actions': [],
'result': {'type': 'form', 'arch': view_form_update, 'fields': fields,
'state': [
('company', 'Previous', 'gtk-go-back'),
('finish', 'Install', 'gtk-ok', True)
]
}
},
'finish':{
'actions': [_update],
'result': {'type': 'form', 'arch': view_form_finish, 'fields': {},
'state': [
('menu', 'Use Directly'),
('config', 'Start Configuration', 'gtk-ok', True)
]
}
},
'config': {
'result': {
'type': 'action',
'action': _config,
'state': 'end',
},
},
'menu': {
'actions': [],
'result': {'type': 'action', 'action': _menu, 'state': 'end'}
},
}
'menu': {
'actions': [],
'result': {'type': 'action', 'action': _menu, 'state': 'end'}
},
}
wizard_base_setup('base_setup.base_setup')

View File

@ -26,12 +26,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "VAT",
"version" : "1.0",
"author" : "Tiny",
"category" : "Generic Modules/Base",
"depends" : ["base"],
"update_xml" : ["base_vat_data.xml"],
"active": False,
"installable": True
"name" : "VAT",
"version" : "1.0",
"author" : "Tiny",
"category" : "Generic Modules/Base",
"depends" : ["base"],
"update_xml" : ["base_vat_data.xml"],
"active": False,
"installable": True
}

View File

@ -26,14 +26,14 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name":"Dashboard main module",
"version":"1.0",
"author":"Tiny",
"category":"Board/Base",
"depends":["base"],
"demo_xml":[],
"update_xml":["board_view.xml"],
"description": "Base module for all dashboards.",
"active":False,
"installable":True,
"name":"Dashboard main module",
"version":"1.0",
"author":"Tiny",
"category":"Board/Base",
"depends":["base"],
"demo_xml":[],
"update_xml":["board_view.xml"],
"description": "Base module for all dashboards.",
"active":False,
"installable":True,
}

View File

@ -31,94 +31,94 @@ import time
from osv import fields,osv
class board_board(osv.osv):
_name = 'board.board'
def create(self, cr, user, vals, context=None):
if not 'name' in vals:
return False
return super(board_board, self).create(cr, user, vals, context)
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
if context and ('view' in context):
board = self.pool.get('board.board').browse(cr, user, int(context['view']), context)
left = []
right = []
for line in board.line_ids:
linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
if line.height:
linestr+=(' height="%d"' % (line.height,))
if line.width:
linestr+=(' width="%d"' % (line.width,))
linestr += '/>'
if line.position=='left':
left.append(linestr)
else:
right.append(linestr)
arch = """<form string="My Board">
_name = 'board.board'
def create(self, cr, user, vals, context=None):
if not 'name' in vals:
return False
return super(board_board, self).create(cr, user, vals, context)
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
if context and ('view' in context):
board = self.pool.get('board.board').browse(cr, user, int(context['view']), context)
left = []
right = []
for line in board.line_ids:
linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
if line.height:
linestr+=(' height="%d"' % (line.height,))
if line.width:
linestr+=(' width="%d"' % (line.width,))
linestr += '/>'
if line.position=='left':
left.append(linestr)
else:
right.append(linestr)
arch = """<form string="My Board">
<hpaned>
<child1>
%s
</child1>
<child2>
%s
</child2>
<child1>
%s
</child1>
<child2>
%s
</child2>
</hpaned>
</form>""" % ('\n'.join(left), '\n'.join(right))
result = {
'toolbar': {'print':[],'action':[],'relate':[]},
'fields': {},
'arch': arch
}
return result
res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
res['toolbar'] = {'print':[],'action':[],'relate':[]}
return res
_columns = {
'name': fields.char('Dashboard', size=64, required=True),
'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
}
result = {
'toolbar': {'print':[],'action':[],'relate':[]},
'fields': {},
'arch': arch
}
return result
res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
res['toolbar'] = {'print':[],'action':[],'relate':[]}
return res
_columns = {
'name': fields.char('Dashboard', size=64, required=True),
'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
}
board_board()
class board_line(osv.osv):
_name = 'board.board.line'
_order = 'position,sequence'
_columns = {
'name': fields.char('Board', size=64, required=True),
'sequence': fields.integer('Sequence'),
'height': fields.integer('Height'),
'width': fields.integer('Width'),
'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
'position': fields.selection([('left','Left'),('right','Right')], 'Position', required=True)
}
_defaults = {
'position': lambda *args: 'left'
}
_name = 'board.board.line'
_order = 'position,sequence'
_columns = {
'name': fields.char('Board', size=64, required=True),
'sequence': fields.integer('Sequence'),
'height': fields.integer('Height'),
'width': fields.integer('Width'),
'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
'position': fields.selection([('left','Left'),('right','Right')], 'Position', required=True)
}
_defaults = {
'position': lambda *args: 'left'
}
board_line()
class board_note_type(osv.osv):
_name = 'board.note.type'
_columns = {
'name': fields.char('Note Type', size=64, required=True),
}
_name = 'board.note.type'
_columns = {
'name': fields.char('Note Type', size=64, required=True),
}
board_note_type()
def _type_get(self, cr, uid, context={}):
obj = self.pool.get('board.note.type')
ids = obj.search(cr, uid, [])
res = obj.read(cr, uid, ids, ['name'], context)
res = [(r['name'], r['name']) for r in res]
return res
obj = self.pool.get('board.note.type')
ids = obj.search(cr, uid, [])
res = obj.read(cr, uid, ids, ['name'], context)
res = [(r['name'], r['name']) for r in res]
return res
class board_note(osv.osv):
_name = 'board.note'
_columns = {
'name': fields.char('Subject', size=128, required=True),
'note': fields.text('Note'),
'user_id': fields.many2one('res.users', 'Author', size=64),
'date': fields.date('Date', size=64, required=True),
'type': fields.selection(_type_get, 'Note type', size=64),
}
_defaults = {
'user_id': lambda object,cr,uid,context: uid,
'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
}
_name = 'board.note'
_columns = {
'name': fields.char('Subject', size=128, required=True),
'note': fields.text('Note'),
'user_id': fields.many2one('res.users', 'Author', size=64),
'date': fields.date('Date', size=64, required=True),
'type': fields.selection(_type_get, 'Note type', size=64),
}
_defaults = {
'user_id': lambda object,cr,uid,context: uid,
'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
}
board_note()

View File

@ -35,47 +35,47 @@ import pooler
section_form = '''<?xml version="1.0"?>
<form string="Create Menu For Dashboard">
<separator string="Menu Information" colspan="4"/>
<field name="menu_name"/>
<field name="menu_parent_id"/>
<separator string="Menu Information" colspan="4"/>
<field name="menu_name"/>
<field name="menu_parent_id"/>
</form>'''
section_fields = {
'menu_name': {'string':'Menu Name', 'type':'char', 'required':True, 'size':64},
'menu_parent_id': {'string':'Parent Menu', 'type':'many2one', 'relation':'ir.ui.menu', 'required':True},
'menu_name': {'string':'Menu Name', 'type':'char', 'required':True, 'size':64},
'menu_parent_id': {'string':'Parent Menu', 'type':'many2one', 'relation':'ir.ui.menu', 'required':True},
}
def board_menu_create(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
board = pool.get('board.board').browse(cr, uid, data['id'])
action_id = pool.get('ir.actions.act_window').create(cr, uid, {
'name': board.name,
'view_type':'form',
'view_mode':'form',
'context': "{'view':%d}" % (board.id,),
'res_model': 'board.board'
})
pool.get('ir.ui.menu').create(cr, uid, {
'name': data['form']['menu_name'],
'parent_id': data['form']['menu_parent_id'],
'icon': 'STOCK_SELECT_COLOR',
'action': 'ir.actions.act_window,'+str(action_id)
}, context)
return {}
pool = pooler.get_pool(cr.dbname)
board = pool.get('board.board').browse(cr, uid, data['id'])
action_id = pool.get('ir.actions.act_window').create(cr, uid, {
'name': board.name,
'view_type':'form',
'view_mode':'form',
'context': "{'view':%d}" % (board.id,),
'res_model': 'board.board'
})
pool.get('ir.ui.menu').create(cr, uid, {
'name': data['form']['menu_name'],
'parent_id': data['form']['menu_parent_id'],
'icon': 'STOCK_SELECT_COLOR',
'action': 'ir.actions.act_window,'+str(action_id)
}, context)
return {}
class wizard_section_menu_create(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':section_form, 'fields':section_fields, 'state':[('end','Cancel'),('create_menu','Create Menu')]}
},
'create_menu': {
'actions': [board_menu_create],
'result': {
'type':'state',
'state':'end'
}
}
}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':section_form, 'fields':section_fields, 'state':[('end','Cancel'),('create_menu','Create Menu')]}
},
'create_menu': {
'actions': [board_menu_create],
'result': {
'type':'state',
'state':'end'
}
}
}
wizard_section_menu_create('board.board.menu.create')

View File

@ -26,30 +26,30 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name":"Board for accountant",
"version":"1.0",
"author":"Tiny",
"category":"Board/Accounting",
"depends":[
"account",
"hr_timesheet_invoice",
"board",
"report_account",
"report_analytic",
"report_analytic_line",
"account_report",
],
"demo_xml":["board_account_demo.xml"],
"update_xml":["board_account_view.xml"],
"description": """
This module creates a dashboards for accountants that includes:
* List of analytic accounts to close
* List of uninvoiced quotations
* List of invoices to confirm
* Graph of costs to invoice
* Graph of aged receivables
* Graph of aged incomes
""",
"active":False,
"installable":True,
"name":"Board for accountant",
"version":"1.0",
"author":"Tiny",
"category":"Board/Accounting",
"depends":[
"account",
"hr_timesheet_invoice",
"board",
"report_account",
"report_analytic",
"report_analytic_line",
"account_report",
],
"demo_xml":["board_account_demo.xml"],
"update_xml":["board_account_view.xml"],
"description": """
This module creates a dashboards for accountants that includes:
* List of analytic accounts to close
* List of uninvoiced quotations
* List of invoices to confirm
* Graph of costs to invoice
* Graph of aged receivables
* Graph of aged incomes
""",
"active":False,
"installable":True,
}

View File

@ -26,29 +26,29 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name":"Board for project users",
"version":"1.0",
"author":"Tiny",
"category":"Board/Projects & Services",
"depends":[
"project",
"report_timesheet",
"board",
"report_analytic_planning",
"report_analytic_line",
"report_task",
"hr_timesheet_sheet"
],
"demo_xml":["board_project_demo.xml"],
"update_xml":["board_project_view.xml", "board_project_manager_view.xml"],
"description": """
"name":"Board for project users",
"version":"1.0",
"author":"Tiny",
"category":"Board/Projects & Services",
"depends":[
"project",
"report_timesheet",
"board",
"report_analytic_planning",
"report_analytic_line",
"report_task",
"hr_timesheet_sheet"
],
"demo_xml":["board_project_demo.xml"],
"update_xml":["board_project_view.xml", "board_project_manager_view.xml"],
"description": """
This module implements a dashboard for project member that includes:
* List of my open tasks
* List of my next deadlines
* List of public notes
* Graph of my timesheet
* Graph of my work analysis
""",
"active":False,
"installable":True,
* List of my open tasks
* List of my next deadlines
* List of public notes
* Graph of my timesheet
* Graph of my work analysis
""",
"active":False,
"installable":True,
}

View File

@ -26,21 +26,21 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name":"Dashboard for sales",
"version":"1.0",
"author":"Tiny",
"category":"Board/Sales & Purchase",
"depends":["board","sale", "report_crm", "report_sale"],
"demo_xml":["board_sale_demo.xml"],
"update_xml":["board_sale_view.xml"],
"description": """
"name":"Dashboard for sales",
"version":"1.0",
"author":"Tiny",
"category":"Board/Sales & Purchase",
"depends":["board","sale", "report_crm", "report_sale"],
"demo_xml":["board_sale_demo.xml"],
"update_xml":["board_sale_view.xml"],
"description": """
This module implements a dashboard for salesman that includes:
* You open quotations
* Top 10 sales of the month
* Cases statistics
* Graph of sales by product
* Graph of cases of the month
""",
"active":False,
"installable":True,
* You open quotations
* Top 10 sales of the month
* Cases statistics
* Graph of sales by product
* Graph of cases of the month
""",
"active":False,
"installable":True,
}

View File

@ -26,12 +26,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
{
"name" : "Customer & Supplier Relationship Management",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com/module_crm.html",
"category" : "Generic Modules/CRM & SRM",
"description": """The Tiny ERP case and request tracker enables a group of
"name" : "Customer & Supplier Relationship Management",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com/module_crm.html",
"category" : "Generic Modules/CRM & SRM",
"description": """The Tiny ERP case and request tracker enables a group of
people to intelligently and efficiently manage tasks, issues, and requests.
It manages key tasks such as communication, identification, prioritization,
assignment, resolution and notification.
@ -48,10 +48,10 @@ place.
The CRM module has a email gateway for the synchronisation interface
between mails and Tiny ERP.""",
"depends" : ["base"],
"init_xml" : ["crm_data.xml"],
"demo_xml" : ["crm_demo.xml"],
"update_xml" : ["crm_view.xml", "crm_report.xml", "crm_wizard.xml", "crm_security.xml"],
"active": False,
"installable": True
"depends" : ["base"],
"init_xml" : ["crm_data.xml"],
"demo_xml" : ["crm_demo.xml"],
"update_xml" : ["crm_view.xml", "crm_report.xml", "crm_wizard.xml", "crm_security.xml"],
"active": False,
"installable": True
}

Some files were not shown because too many files have changed in this diff Show More