Skip to content

Commit

Permalink
✨✅ Now check for related soci instead of titular
Browse files Browse the repository at this point in the history
  • Loading branch information
pauboixsom committed Feb 11, 2025
1 parent 01b5e75 commit 1947172
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions som_generationkwh/somenergia_soci.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ def verifica_baixa_soci(self, cursor, uid, ids, context=None):
raise osv.except_osv(_('El soci no pot ser donat de baixa!'), _('El soci té factures pendents.'))

polisses = pol_obj.search(cursor, uid,
[('titular', '=', res_partner_id),
[('soci', '=', res_partner_id),
('state', '!=', 'baixa'),
('state', '!=', 'cancelada')])
if polisses:
raise osv.except_osv(_('El soci no pot ser donat de baixa!'), _('El soci té al menys un contracte actiu.'))
raise osv.except_osv(_('El soci no pot ser donat de baixa!'), _('El soci té al menys un contracte vinculat.'))

soci_category_id = imd_obj.get_object_reference(
cursor, uid, 'som_partner_account', 'res_partner_category_soci'
Expand Down
32 changes: 26 additions & 6 deletions som_generationkwh/tests/somenergia_soci_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def test_cancel_member_with_pending_invoices__notAllowed(self):
self.assertEqual(ctx.exception.message,
"warning -- El soci no pot ser donat de baixa!\n\nEl soci té factures pendents.")

def test_cancel_member_with_active_contract__notAllowed(self):
def test_cancel_member_with_active_contract__Allowed(self):
partner_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'res_partner_inversor1'
self.cursor, self.uid, 'som_generationkwh', 'res_partner_inversor1'
)[1]
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
invs = self.Investment.search(self.cursor, self.uid, [('member_id','=', member_id)])
Expand All @@ -103,14 +103,34 @@ def test_cancel_member_with_active_contract__notAllowed(self):
polissa_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'giscedata_polissa', 'polissa_0001'
)[1]

self.Polissa.write(self.cursor, self.uid, [polissa_id], {'titular': partner_id})


self.assertEqual(self.Soci.verifica_baixa_soci(self.cursor, self.uid, member_id), True)

def test_cancel_member_with_related_contract__notAllowed(self):
partner_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'res_partner_inversor1'
)[1]
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
invs = self.Investment.search(self.cursor, self.uid, [('member_id','=', member_id)])

self.Investment.write(self.cursor, self.uid, invs, {'active':False})

polissa_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'giscedata_polissa', 'polissa_0001'
)[1]

self.Polissa.write(self.cursor, self.uid, [polissa_id], {'soci': partner_id})

with self.assertRaises(except_osv) as ctx:
self.Soci.verifica_baixa_soci(self.cursor, self.uid, member_id)

self.assertEqual(ctx.exception.message,
"warning -- El soci no pot ser donat de baixa!\n\nEl soci té al menys un contracte actiu.")
"warning -- El soci no pot ser donat de baixa!\n\nEl soci té al menys un contracte vinculat.")


@mock.patch("som_polissa_soci.res_partner_address.ResPartnerAddress.archieve_mail_in_list")
Expand Down

0 comments on commit 1947172

Please sign in to comment.