Add receivable/payable on partner
This commit is contained in:
1 parent
05a8d28145
commit
c3df295908
2 files changed
+147
-1
No files matched your search
@@ -400,7 +400,7 @@ class Line(OSV):
|
||||
name: value,
|
||||
}, context=context)
|
||||
|
||||
def search_move_field(cursor, user, obj, name, args, context=None):
|
||||
def search_move_field(self, cursor, user, name, args, context=None):
|
||||
args2 = []
|
||||
i = 0
|
||||
while i < len(args):
|
||||
@@ -771,3 +771,113 @@ class OpenAccount(Wizard):
|
||||
return res
|
||||
|
||||
OpenAccount()
|
||||
|
||||
|
||||
class Partner(OSV):
|
||||
_name = 'partner.partner'
|
||||
receivable = fields.Function('get_receivable_payable',
|
||||
fnct_search='search_receivable_payable', string='Receivable')
|
||||
payable = fields.Function('get_receivable_payable',
|
||||
fnct_search='search_receivable_payable', string='Payable')
|
||||
|
||||
def get_receivable_payable(self, cursor, user_id, ids, name, arg,
|
||||
context=None):
|
||||
res = {}
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
company_obj = self.pool.get('company.company')
|
||||
user_obj = self.pool.get('res.user')
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if name not in ('receivable', 'payable'):
|
||||
raise Exception('Bad argument')
|
||||
|
||||
for i in ids:
|
||||
res[i] = Decimal('0.0')
|
||||
|
||||
company_id = None
|
||||
user = user_obj.browse(cursor, user_id, user_id, context=context)
|
||||
if context.get('company'):
|
||||
child_company_ids = company_obj.search(cursor, user_id, [
|
||||
('parent', 'child_of', [user.main_company.id]),
|
||||
], context=context)
|
||||
if context['company'] in child_company_ids:
|
||||
company_id = context['company']
|
||||
|
||||
if not company_id:
|
||||
company_id = user.company.id or user.main_company.id
|
||||
|
||||
if not company_id:
|
||||
return res
|
||||
|
||||
line_query = move_line_obj.query_get(cursor, user_id, context=context)
|
||||
|
||||
cursor.execute('SELECT l.partner, ' \
|
||||
'SUM((COALESCE(l.debit, 0) - COALESCE(l.credit, 0))) ' \
|
||||
'FROM account_move_line AS l, ' \
|
||||
'account_account AS a ' \
|
||||
'WHERE a.id = l.account ' \
|
||||
'AND a.active ' \
|
||||
'AND a.type = %s ' \
|
||||
'AND l.partner IN ' \
|
||||
'(' + ','.join(['%s' for x in ids]) + ') ' \
|
||||
#TODO add reconcile clause
|
||||
'AND ' + line_query + ' ' \
|
||||
'AND a.company = %s ' \
|
||||
'GROUP BY l.partner', (name,) + tuple(ids) + (company_id,))
|
||||
for partner_id, sum in cursor.fetchall():
|
||||
res[partner_id] = sum
|
||||
return res
|
||||
|
||||
def search_receivable_payable(self, cursor, user_id, name, args,
|
||||
context=None):
|
||||
if not len(args):
|
||||
return []
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
company_obj = self.pool.get('company.company')
|
||||
user_obj = self.pool.get('res.user')
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if name not in ('receivable', 'payable'):
|
||||
raise Exception('Bad argument')
|
||||
|
||||
company_id = None
|
||||
user = user_obj.browse(cursor, user_id, user_id, context=context)
|
||||
if context.get('company'):
|
||||
child_company_ids = company_obj.search(cursor, user_id, [
|
||||
('parent', 'child_of', [user.main_company.id]),
|
||||
], context=context)
|
||||
if context['company'] in child_company_ids:
|
||||
company_id = context['company']
|
||||
|
||||
if not company_id:
|
||||
company_id = user.company.id or user.main_company.id
|
||||
|
||||
if not company_id:
|
||||
return []
|
||||
|
||||
line_query = move_line_obj.query_get(cursor, user_id, context=context)
|
||||
|
||||
cursor.execute('SELECT l.partner ' \
|
||||
'FROM account_move_line AS l, ' \
|
||||
'account_account AS a ' \
|
||||
'WHERE a.id = l.account ' \
|
||||
'AND a.active ' \
|
||||
'AND a.type = %s ' \
|
||||
'AND l.partner IS NOT NULL ' \
|
||||
#TODO add reconcile clause
|
||||
'AND ' + line_query + ' ' \
|
||||
'AND a.company = %s ' \
|
||||
'GROUP BY l.partner ' \
|
||||
'HAVING ' + \
|
||||
'AND'.join(['(SUM((COALESCE(l.debit, 0) - COALESCE(l.credit, 0))) ' \
|
||||
+ ' ' + x[1] + ' ' + str(x[2]) + ') ' for x in args]),
|
||||
(name, company_id))
|
||||
if not cursor.rowcount:
|
||||
return [('id', '=', 0)]
|
||||
return [('id', 'in', [x[0] for x in cursor.fetchall()])]
|
||||
|
||||
Partner()
|
||||
@@ -177,5 +177,41 @@
|
||||
</record>
|
||||
<menuitem parent="menu_entries" action="act_open_journal"
|
||||
icon="STOCK_INDENT" id="menu_open_journal"/>
|
||||
<record model="ir.ui.view" id="partner_view_tree">
|
||||
<field name="model">partner.partner</field>
|
||||
<field name="inherit" ref="partner.partner_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath
|
||||
expr="/tree/field[@name="vat"]"
|
||||
position="after">
|
||||
<field name="receivable" select="2"/>
|
||||
<field name="payable" select="2"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="partner_view_form">
|
||||
<field name="model">partner.partner</field>
|
||||
<field name="inherit" ref="partner.partner_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@string="General"]"
|
||||
position="after">
|
||||
<page string="Accounting">
|
||||
<label name="receivable"/>
|
||||
<field name="receivable"/>
|
||||
<label name="payable"/>
|
||||
<field name="payable"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
Reference in new issue
Block a user