Skip to content

Commit

Permalink
[FIX] account_payment_pro: multiple fixes in usability of this module
Browse files Browse the repository at this point in the history
closes #505

Related: ingadhoc/multi-company#160
Signed-off-by: Filoquin adhoc <[email protected]>
  • Loading branch information
rov-adhoc committed Jul 31, 2024
1 parent 144816d commit 8990441
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion account_payment_pro/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Payment Super Power",
"version": "17.0.1.4.0",
"version": "17.0.1.5.0",
"category": "Payment",
"website": "www.adhoc.com.ar",
"author": "ADHOC SA",
Expand Down
2 changes: 1 addition & 1 deletion account_payment_pro/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _compute_payment_matched_amount(self):
rec.payment_matched_amount = debit_move_amount - credit_move_amount

def action_register_payment(self):
if not self.company_id.use_payment_pro:
if len(self.company_id.ids)>1 or not self.company_id.use_payment_pro:
return super().action_register_payment()

to_pay_move_lines = self.filtered(
Expand Down
46 changes: 28 additions & 18 deletions account_payment_pro/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,20 @@ def _get_confimed_blocked_field(self):
'withholdable_advanced_amount', 'company_id', 'to_pay_amount']

def write(self, vals):
if self.filtered('is_approved'):
if set(vals) & set(self._get_confimed_blocked_field()):
raise UserError(_('Your are trying to modify a protected field on an approved payment. Set it back to edit if you want to make this modification.'))
if self.company_id.use_payment_pro:
# Lo siguiente lo evaluamos para evitar la validacion de odoo de
# https://github.com/odoo/odoo/blob/b6b90636938ae961c339807ea893cabdede9f549/addons/account/models/account_move.py#L2476
# y permitirnos realizar la modificacion del journal.
if 'journal_id' in vals and self.journal_id.id != vals['journal_id']:
self.move_id.sequence_number = 0

# Lo siguiente lo agregamos para primero obligarnos a cambiar el journal_id y no la company_id. Una vez cambiado el journal_id
# la company_id se cambia correctamente.
if 'company_id' in vals and 'journal_id' in vals:
self.move_id.journal_id = vals['journal_id']
if self.filtered('is_approved') and set(self) & set(self._get_confimed_blocked_field()):
raise UserError(_('Your are trying to modify a protected field on an approved payment. Set it back to edit if you want to make this modification.'))
for rec in self:
if rec.company_id.use_payment_pro or ('company_id' in vals and rec.env['res.company'].browse(vals['company_id']).use_payment_pro):
# Lo siguiente lo evaluamos para evitar la validacion de odoo de
# https://github.com/odoo/odoo/blob/b6b90636938ae961c339807ea893cabdede9f549/addons/account/models/account_move.py#L2476
# y permitirnos realizar la modificacion del journal.
if 'journal_id' in vals and rec.journal_id.id != vals['journal_id']:
rec.move_id.sequence_number = 0

# Lo siguiente lo agregamos para primero obligarnos a cambiar el journal_id y no la company_id. Una vez cambiado el journal_id
# la company_id se cambia correctamente.
if 'company_id' in vals and 'journal_id' in vals:
rec.move_id.journal_id = vals['journal_id']
return super().write(vals)

@api.depends('company_id.double_validation', 'partner_type')
Expand Down Expand Up @@ -220,8 +220,11 @@ def _compute_requiere_double_validation(self):
# pay.payment_type == 'inbound' else [('outbound_payment_method_line_ids', '!=', False)]
# pay.available_journal_ids = journals.filtered_domain(filtered_domain)

@api.onchange('company_id')
def _compute_available_journal_ids(self):
# Cambiamos el metodo para que traiga los journal de la compañia sobre la cual se esta imputando el pago
# Cambiamos el metodo para que traiga los journals de la compañia sobre la cual se esta imputando el pago.
# Le agregamos el onchange de company para asegurarnos de que los available journals se computen siempre
# que se produce un cambio de compañia
self.env.company = self.company_id
super()._compute_available_journal_ids()

Expand Down Expand Up @@ -488,7 +491,10 @@ def _compute_to_pay_move_lines(self):

# Se recomputan las lienas solo si la deuda que esta seleccionada solo si
# cambio el partner, compania o partner_type
for rec in self.filtered(lambda x: x.company_id.use_payment_pro==True):

with_payment_pro = self.filtered(lambda x: x.company_id.use_payment_pro)
(self - with_payment_pro).to_pay_move_line_ids = [Command.clear()]
for rec in with_payment_pro:
if rec.partner_id != rec._origin.partner_id or rec.partner_type != rec._origin.partner_type or \
rec.company_id != rec._origin.company_id:
rec.add_all()
Expand All @@ -507,7 +513,7 @@ def _get_to_pay_move_lines_domain(self):

def add_all(self):
for rec in self:
rec.to_pay_move_line_ids = [Command.clear(), Command.set(self.env['account.move.line'].search(rec._get_to_pay_move_lines_domain()).ids)]
rec.to_pay_move_line_ids = [Command.clear(), Command.set(self.env['account.move.line'].search(rec.with_context(active_ids=False)._get_to_pay_move_lines_domain()).ids)]

def remove_all(self):
self.to_pay_move_line_ids = False
Expand Down Expand Up @@ -542,4 +548,8 @@ def web_read(self, specification):
if 'matched_move_line_ids' in fields_to_read and 'context' in specification['matched_move_line_ids']:
specification['matched_move_line_ids']['context'].update({'matched_payment_ids': self._ids})
return super().web_read(specification)


@api.onchange('selected_debt')
def onchange_selected_debt(self):
for rec in self:
rec.amount = rec.selected_debt
2 changes: 1 addition & 1 deletion account_payment_pro/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<field name="use_payment_pro" invisible="True"/>
</form>
<field name="journal_id" position="before">
<field name="company_id" options="{'no_create': True}" domain="[('id', 'in', allowed_company_ids)]" groups="base.group_multi_company" readonly="state != 'draft'"/>
<field name="company_id" options="{'no_create': True}" domain="[('id', 'in', allowed_company_ids)]" groups="base.group_multi_company" readonly="state != 'draft' or context.get('default_company_id')"/>
</field>
<xpath expr="//div[@name='button_box']" position="after">
<span class="badge rounded-pill text-bg-warning float-end fs-6" invisible="not requiere_double_validation">
Expand Down

0 comments on commit 8990441

Please sign in to comment.