mirror of
https://gitlab.com/datalifeit/trytond-account_bank
synced 2023-12-14 06:23:07 +01:00
Allow searching potential moves for netting.
(grafted from f61e08329ae83eb057d5dcf30b2f8cdaf04a2ee5)
This commit is contained in:
parent
b1523ac0dd
commit
8b6a5e8ee3
3 changed files with 90 additions and 7 deletions
55
account.py
55
account.py
|
@ -384,6 +384,8 @@ class Line:
|
|||
|
||||
reverse_moves = fields.Function(fields.Boolean('With Reverse Moves'),
|
||||
'get_reverse_moves', searcher='search_reverse_moves')
|
||||
netting_moves = fields.Function(fields.Boolean('With Netting Moves'),
|
||||
'get_netting_moves', searcher='search_netting_moves')
|
||||
|
||||
def get_reverse_moves(self, name):
|
||||
if (not self.account
|
||||
|
@ -434,6 +436,53 @@ class Line:
|
|||
cursor.execute(query)
|
||||
return [('id', operator, [x[0] for x in cursor.fetchall()])]
|
||||
|
||||
def get_netting_moves(self, name):
|
||||
if (not self.account or not self.account.kind in
|
||||
['receivable', 'payable']):
|
||||
return False
|
||||
if not self.account.party_required:
|
||||
return False
|
||||
domain = [
|
||||
('party', '=', self.party.id),
|
||||
('reconciliation', '=', None),
|
||||
]
|
||||
if self.credit > Decimal('0.0'):
|
||||
domain.append(('debit', '>', 0))
|
||||
if self.debit > Decimal('0.0'):
|
||||
domain.append(('credit', '>', 0))
|
||||
moves = self.search(domain, limit=1)
|
||||
return len(moves) > 0
|
||||
|
||||
@classmethod
|
||||
def search_netting_moves(cls, name, clause):
|
||||
operator = 'in' if clause[2] else 'not in'
|
||||
query = """
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
account_move_line l
|
||||
WHERE
|
||||
party IN (
|
||||
SELECT
|
||||
aml.party
|
||||
FROM
|
||||
account_account aa,
|
||||
account_move_line aml
|
||||
WHERE
|
||||
aa.reconcile
|
||||
AND aa.id = aml.account
|
||||
AND aml.reconciliation IS NULL
|
||||
GROUP BY
|
||||
aml.party
|
||||
HAVING
|
||||
bool_or(aml.debit <> 0)
|
||||
AND bool_or(aml.credit <> 0)
|
||||
)
|
||||
"""
|
||||
cursor = Transaction().cursor
|
||||
cursor.execute(query)
|
||||
return [('id', operator, [x[0] for x in cursor.fetchall()])]
|
||||
|
||||
|
||||
class CompensationMoveStart(ModelView):
|
||||
'Create Compensation Move Start'
|
||||
|
@ -476,7 +525,8 @@ class CompensationMoveStart(ModelView):
|
|||
company = None
|
||||
amount = Decimal('0.0')
|
||||
|
||||
for line in Line.browse(Transaction().context.get('active_ids', [])):
|
||||
lines = Line.browse(Transaction().context.get('active_ids', []))
|
||||
for line in lines:
|
||||
amount += line.debit - line.credit
|
||||
if not party:
|
||||
party = line.party
|
||||
|
@ -485,7 +535,8 @@ class CompensationMoveStart(ModelView):
|
|||
line.rec_name, party.rec_name))
|
||||
if not company:
|
||||
company = line.account.company
|
||||
if company and company.currency.is_zero(amount):
|
||||
if (company and company.currency.is_zero(amount)
|
||||
and len(set([x.account for x in lines])) == 1):
|
||||
cls.raise_user_error('normal_reconcile')
|
||||
return defaults
|
||||
res['account'] = (party.account_receivable.id
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
|
@ -10,6 +10,14 @@ msgstr ""
|
|||
"%s no té cap compte bancari %s.\n"
|
||||
"Si us plau, establiu un si voleu utilitzar aquest tipus de pagament."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" cannot be moved to \"Draft\" state because it is "
|
||||
"already used in statement line \"%(statement_line)s\"."
|
||||
msgstr ""
|
||||
"La factura \"%(invoice)s\" no es pot passar a estat \"Esborrany\" perquè ja "
|
||||
"s'utilitza en la línia d'extracte \"%(statement_line)s\"."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" has no bank account associated but payment type "
|
||||
|
@ -89,6 +97,14 @@ msgctxt "field:account.invoice,bank_account:"
|
|||
msgid "Bank Account"
|
||||
msgstr "Compte bancari"
|
||||
|
||||
msgctxt "field:account.move.compensation_move.start,account:"
|
||||
msgid "Account"
|
||||
msgstr "Compte"
|
||||
|
||||
msgctxt "field:account.move.compensation_move.start,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
msgctxt "field:account.move.compensation_move.start,id:"
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
@ -119,11 +135,11 @@ msgstr "Tercer"
|
|||
|
||||
msgctxt "model:account.move.compensation_move.start,name:"
|
||||
msgid "Create Compensation Move Start"
|
||||
msgstr "Inici crea efecte de compensació"
|
||||
msgstr "Inici crea assentament de compensació"
|
||||
|
||||
msgctxt "model:ir.action,name:act_compensation_move_lines"
|
||||
msgid "Create compensation move"
|
||||
msgstr "Crea efecte de compensació"
|
||||
msgstr "Crea assentament de compensació"
|
||||
|
||||
msgctxt "selection:account.invoice,account_bank:"
|
||||
msgid "Company"
|
||||
|
@ -159,7 +175,7 @@ msgstr "Tercer"
|
|||
|
||||
msgctxt "view:account.move.compensation_move.start:"
|
||||
msgid "Create Compensation Move"
|
||||
msgstr "Crea efecte de compensació"
|
||||
msgstr "Crea assentament de compensació"
|
||||
|
||||
msgctxt "wizard_button:account.move.compensation_move,start,create_move:"
|
||||
msgid "Create"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
|
@ -10,6 +10,14 @@ msgstr ""
|
|||
"%s no tiene ninguna cuenta bancaria %s.\n"
|
||||
"Por favor establezca una si quiere utilizar este tipo de pago."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" cannot be moved to \"Draft\" state because it is "
|
||||
"already used in statement line \"%(statement_line)s\"."
|
||||
msgstr ""
|
||||
"La factura \"%(invoice)s\" no se puede pasar a estado \"Borrador\" porqué se"
|
||||
" utiliza en la línea de extracto \"%(statement_line)s\"."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" has no bank account associated but payment type "
|
||||
|
@ -86,6 +94,14 @@ msgctxt "field:account.invoice,bank_account:"
|
|||
msgid "Bank Account"
|
||||
msgstr "Cuenta bancaria"
|
||||
|
||||
msgctxt "field:account.move.compensation_move.start,account:"
|
||||
msgid "Account"
|
||||
msgstr "Cuenta"
|
||||
|
||||
|
||||
msgctxt "field:account.move.compensation_move.start,date:"
|
||||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
msgctxt "field:account.move.compensation_move.start,id:"
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
|
Loading…
Reference in a new issue