modify get collection,

add field origin, move, description
for validate number payments pending in credits
This commit is contained in:
Wilson Gomez 2023-03-02 08:26:25 -05:00
parent f6ec025326
commit 6723610196
6 changed files with 110 additions and 105 deletions

View File

@ -102,11 +102,9 @@ class Tracking(ModelSQL, ModelView):
@fields.depends('contact_method', 'collection', '_parent_collection.party')
def on_change_with_contact(self, name=None):
contact_method = self.contact_method
print(contact_method, 'ingresa', self.collection)
if contact_method and self.collection:
if contact_method == 'msm':
contact_method = 'mobile'
print(contact_method, self.collection.party, 'ingresa')
return self.collection.party.get_mechanism(contact_method)
@ -147,23 +145,24 @@ class Collection(ModelSQL, ModelView):
'Collection'
__name__ = 'collection.collection'
company = fields.Many2One('company.company', 'Company', required=True,
help="Make the collection belong to the company.",
select=True, domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
],
states=_STATES, depends=_DEPENDS)
help="Make the collection belong to the company.",
select=True, domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
],
states=_STATES, depends=_DEPENDS)
description = fields.Char('Description')
line = fields.Many2One('account.move.line', 'Move Line', required=True,
help="The receivable line to dun for.",
domain=[
('account.type.receivable', '=', 'true'),
('account.company', '=', Eval('company', -1)),
['OR',
('debit', '>', 0),
('credit', '<', 0),
],
],
states=_STATES, depends=_DEPENDS + ['company'])
help="The receivable line to dun for.",
domain=[
('account.type.receivable', '=', 'true'),
('account.company', '=', Eval('company', -1)),
['OR',
('debit', '>', 0),
('credit', '<', 0),
],
],
states=_STATES, depends=_DEPENDS + ['company'])
procedure = fields.Many2One('collection.procedure', 'Procedure',
states=_STATES, depends=_DEPENDS)
level = fields.Function(fields.Many2One(
@ -184,25 +183,28 @@ class Collection(ModelSQL, ModelView):
('cancel', "Cancel"),
], 'State', readonly=True)
party = fields.Many2One('party.party', 'Party')
invoice = fields.Function(fields.Many2One('account.invoice', 'Invoice'),
'get_invoice')
origin = fields.Function(fields.Reference('Origin',
selection=[
('', ''),
('account.invoice', 'account.invoice'),
], translate=False), 'get_origin')
amount = fields.Function(fields.Numeric('Amount Total',
digits=(
16, Eval('currency_digits', 2)),
depends=['currency_digits']),
'get_amount')
digits=(
16, Eval('currency_digits', 2)),
depends=['currency_digits']),
'get_amount')
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'get_line_field')
'get_line_field')
maturity_date = fields.Function(fields.Date('Maturity Date'),
'get_line_field', searcher='search_line_field')
'get_line_field', searcher='search_line_field')
expired_days = fields.Function(fields.Numeric('Expired Days'),
'get_expired_days')
'get_expired_days')
total_payment = fields.Function(fields.Numeric('Total Payment'),
'get_total_payment')
'get_total_payment')
pending_payment = fields.Function(fields.Numeric('Pending Payment'),
'get_pending_payment')
'get_pending_payment')
payments = fields.Function(fields.One2Many('account.move.line', None,
'Payments'), 'get_payments')
'Payments'), 'get_payments')
tracking = fields.One2Many(
'collection.tracking', 'collection', 'Tracking',)
amount_second_currency = fields.Function(fields.Numeric(
@ -215,6 +217,8 @@ class Collection(ModelSQL, ModelView):
'Second Currency Digits'), 'get_second_currency_digits')
collection_percent = fields.Function(fields.Numeric(
'Collection Percent', digits=(2, 2), readonly=True), 'get_collection_percent')
move = fields.Many2One("account.move", "Move")
lines_move = fields.Function(fields.One2Many("account.move.line", "move", "Lines"), 'get_lines')
@classmethod
def __setup__(cls):
@ -223,6 +227,20 @@ class Collection(ModelSQL, ModelView):
('line', 'DESC'),
]
@classmethod
def __register__(cls, module_name):
super(Collection, cls).__register__(module_name)
table = cls.__table_handler__(module_name)
if table.column_exist('line'):
cursor = Transaction().connection.cursor()
query = """UPDATE collection_collection
SET move = a.move,
description = a.description
FROM (SELECT id, move, description from account_move_line) as a
WHERE a.id = collection_collection.line
AND collection_collection.move is NULL"""
cursor.execute(query)
@staticmethod
def default_company():
return Transaction().context.get('company')
@ -231,25 +249,12 @@ class Collection(ModelSQL, ModelView):
def default_state():
return 'running'
# @fields.depends('state', 'active')
# def on_change_active(self, name=None):
# if not self.active:
# self.state = 'done'
# @classmethod
# def validate(cls, records):
# for val in records:
# if not val.active:
# cls.write([val], {'state': 'done',})
# def get_state(self, name):
# if self.active:
# return 'running'
# else:
# return 'done'
def get_lines(self, name=None):
return [ml.id for ml in self.move.lines \
if ml.account.type.receivable and self.party == ml.party and self.description == ml.description]
def get_active(self, name):
return not self.line.reconciliation
return all([ml.reconciliation for ml in self.lines_move])
def get_level(self, name):
if self.procedure and self.procedure.levels and self.expired_days:
@ -267,11 +272,18 @@ class Collection(ModelSQL, ModelView):
return level_ids[0].id
def get_line_field(self, name):
value = getattr(self.line, name)
if isinstance(value, Model):
return value.id
else:
return value
line = None
for ml in self.lines_move:
if not ml.reconciliation:
line = ml
break
line = ml
try:
value = getattr(line, name)
except:
print('error', self.id)
value = None
return value
def get_expired_days(self, name):
if self.maturity_date and self.pending_payment != 0:
@ -281,19 +293,19 @@ class Collection(ModelSQL, ModelView):
return None
def get_total_payment(self, name):
if self.line and self.line.move_origin:
return int(sum([pay_line.amount for pay_line in self.line.move_origin.payment_lines]))
if self.move and self.move.origin:
return int(sum([pay_line.amount for pay_line in self.move.origin.payment_lines]))
def get_invoice(self, name):
if self.line and self.line.move_origin:
return self.line.move_origin.id
def get_origin(self, name):
if self.move and self.move.origin:
return str(self.move.origin)
def get_pending_payment(self, name):
return int(self.amount - abs(self.total_payment or Decimal(0.0)))
def get_payments(self, name):
if self.line and self.line.move_origin:
return [l.id for l in self.line.move_origin.payment_lines]
if self.move and self.move.origin:
return [l.id for l in self.move.origin.payment_lines]
def get_collection_percent(self, name):
if self.amount and self.total_payment:
@ -304,7 +316,10 @@ class Collection(ModelSQL, ModelView):
return [('line.' + clause[0],) + tuple(clause[1:])]
def get_amount(self, name):
return self.line.debit - self.line.credit
if self.lines_move:
return sum(line.debit - line.credit for line in self.lines_move)
else:
return 0
def get_amount_second_currency(self, name):
amount = self.line.debit - self.line.credit
@ -395,15 +410,16 @@ class Collection(ModelSQL, ModelView):
# cls.write(*to_write)
lines = MoveLine.search(cls._overdue_line_domain(date))
line_ids = [l.id for l in lines]
lines_exist = cls.search([('line', 'in', line_ids), ])
lines_exist = [l.line.id for l in lines_exist]
collections = (cls._get_collection(line, date)
for line in lines if not line.id in lines_exist)
move_ids = list(set(ml.move.id for ml in lines))
moves = list(set(ml.move for ml in lines))
moves_exist = cls.search([('move', 'in', move_ids), ])
moves_exist = [c.move.id for c in moves_exist]
collections = (cls._get_collection(move, date)
for move in moves if not move.id in moves_exist)
cls.save([d for d in collections if d])
@classmethod
def _get_collection(cls, line, date):
def _get_collection(cls, move, date):
# procedure = line.collection_procedure
# if not procedure:
# return
@ -413,10 +429,10 @@ class Collection(ModelSQL, ModelView):
# else:
# return
return cls(
line=line,
move=move,
procedure=None,
level=None,
party=line.party,
party=move.origin.party,
)
@classmethod

View File

@ -87,6 +87,13 @@ this repository contains the full copyright notices and license terms. -->
<field name="count" eval="True"/>
<field name="act_window" ref="act_collection_form"/>
</record>
<record model="ir.action.act_window.domain" id="act_collection_form_domain_done">
<field name="name">Done</field>
<field name="sequence" eval="30"/>
<field name="domain" eval="[('state', '=', 'done')]" pyson="1"/>
<field name="count" eval="True"/>
<field name="act_window" ref="act_collection_form"/>
</record>
<record model="ir.action.act_window.domain"
id="act_collection_form_domain_all">
<field name="name">All</field>

View File

@ -1373,3 +1373,15 @@ msgstr "Cancelar"
msgctxt "wizard_button:collection.tracking_wizard,start,print_:"
msgid "Print"
msgstr "Imprimir"
msgctxt "field:collection.collection,description:"
msgid "Description"
msgstr "Descripcion"
msgctxt "field:collection.collection,origin:"
msgid "Origin"
msgstr "Origen"
msgctxt "field:collection.collection,lines:"
msgid "Lines"
msgstr "Lineas"

29
view/.gitignore vendored
View File

@ -1,29 +0,0 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/build
/dist
*egg-info
/node_modules
# testing
/coverage
# production
/build
# misc
.DS_Store
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock*
/__pycache__
/app/__pycache__
/app/commons/__pycache__

View File

@ -4,8 +4,8 @@ this repository contains the full copyright notices and license terms. -->
<form>
<label name="party"/>
<field name="party"/>
<label name="invoice"/>
<field name="invoice"/>
<label name="origin"/>
<field name="origin"/>
<label name="maturity_date"/>
<field name="maturity_date"/>
<label name="expired_days"/>
@ -22,8 +22,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="total_payment"/>
<label name="collection_percent" string="Collection Percent (%)"/>
<field name="collection_percent" factor="100"/>
<!-- <label name="blocked"/>
<field name="blocked"/> -->
<label name="description"/>
<field name="description"/>
<notebook colspan="4">
<page string="Trackings" id="trackings">
<field name="tracking" colspan="4"/>
@ -34,8 +34,7 @@ this repository contains the full copyright notices and license terms. -->
<page string="Additional Info" id="add_info">
<label name="company"/>
<field name="company"/>
<label name="line"/>
<field name="line"/>
<field name="lines_move" colspan="4"/>
</page>
</notebook>
<group col="6" colspan="4" id="state">

View File

@ -2,12 +2,12 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<!-- <field name="invoice"/> -->
<field name="party"/>
<field name="origin"/>
<field name="description"/>
<field name="amount"/>
<field name="maturity_date"/>
<field name="expired_days"/>
<field name="procedure"/>
<!-- <field name="blocked"/> -->
<field name="state"/>
</tree>