Skip to content

Commit

Permalink
Merge branch 'master' into NEW_factures_liquidacio_wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
pauboixsom committed Jul 5, 2022
2 parents 4c47e76 + 2075d76 commit ccd7a19
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 253 deletions.
1 change: 0 additions & 1 deletion som_generationkwh/__terp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"wizard/wizard_investment_divest.xml",
"wizard/wizard_investment_transfer.xml",
"wizard/wizard_aeat193_from_gkwh_invoices_view.xml",
"wizard/wizard_send_retencio_estalvi_to_members.xml",
"wizard/wizard_baixa_soci.xml",
"wizard/wizard_contract_sign_signaturit.xml",
"investment_view.xml",
Expand Down
5 changes: 0 additions & 5 deletions som_generationkwh/giscedata_facturacio.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ def apply_gkwh(self, cursor, uid, ids, context=None):
}
)

self.button_reset_taxes(cursor, uid, [inv_id], context=context)

def get_gkwh_lines(self, cursor, uid, ids, context=None):
""" Returns a id list of giscedata.facturacio.factura.linia with
gkwh products
Expand Down Expand Up @@ -591,7 +589,6 @@ def fact_via_lectures(self, cursor, uid, polissa_id, lot_id, context=None):
if can_have_gkwh:
factura_obj.apply_gkwh(cursor, uid, factures, context)
self.reaplica_ajustar_saldo_excedents_autoconsum(cursor, uid, factures, context)
factura_obj.button_reset_taxes(cursor, uid, factures, context=context)
return factures

def create_discount_lines_for_rd_17_2021(self, cursor, uid, fact_ids, context=None):
Expand Down Expand Up @@ -683,8 +680,6 @@ def create_discount_lines_for_rd_17_2021(self, cursor, uid, fact_ids, context=No
tax_ids = [x.id for x in line.invoice_line_tax_id]
line_obj.write(cursor, uid, line_id, {'invoice_line_tax_id': [(6, 0, tax_ids)]})

factura.button_reset_taxes()


GiscedataFacturacioFacturador()

Expand Down
2 changes: 1 addition & 1 deletion som_generationkwh/report/report_retencions_gkwh.mako
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

%for investment in objects :
<%
setLang(report.partner_id.lang)
setLang(report.lang)
%>
<div class="capsalera">
<div class="fila">
Expand Down
49 changes: 5 additions & 44 deletions som_generationkwh/report/report_retencions_gkwh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,21 @@
import logging


class GenerationkwhInvestment(osv.osv):
_name = 'somenergia.soci'
_inherit = 'somenergia.soci'

def send_emails_to_investors_with_savings_in_year(self, cursor, uid, year=None):
"""
Send email to the partners with retencions.rendiment.gkwh report
attached to certificat_retencio_rendiment_generationkwh poweremail template.
Only partners with generationkwh.investment investments that had saving at
given year.
"""
if year is None:
raise Exception("Year must have a value")

pool = pooler.get_pool(cursor.dbname)
Investment = pool.get('generationkwh.investment')

first_day = str(year) + '-01-01'
last_day = str(year) + '-12-31'

all_investments_ids_in_year = Investment.search(cursor, uid, [('first_effective_date', '<=', last_day),
('last_effective_date', '>=', first_day),
('emission_id.type', '=', 'genkwh')])
if all_investments_ids_in_year is None:
raise Exception("No investments found at year {}".format(year))

members = []
for invest_id in all_investments_ids_in_year:
investment = Investment.read(cursor, uid, invest_id, ['member_id'])
members.append(investment['member_id'][0])

members = set(members)
email_params = RetencionsSobreRendimentGenerationKwh.get_email_params(cursor, uid, self)

successfully_sent = 0
for member_id in members:
if RetencionsSobreRendimentGenerationKwh.send_email(cursor, uid, self, member_id, email_params) > 0:
successfully_sent += 1
return successfully_sent

class ResPartner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'

def generationkwh_amortization_data(self, cursor, uid, ids):
if not ids:
raise Exception("No member provided")

member_id = ids[0]
partner_id = ids[0]

report = ns()
pool = pooler.get_pool(cursor.dbname)
Accounts = pool.get('poweremail.core_accounts')
ResPartner = pool.get('res.partner')
ResPartnerAdress = pool.get('res.partner.address')
Soci = pool.get('somenergia.soci')
som_partner_id = 1 # ResPartner.search(cursor, uid, [('vat','=','ESF55091367')])
som_partner = ResPartner.read(cursor, uid, som_partner_id, ['name', 'vat', 'address'])
som_address = ResPartnerAdress.read(cursor, uid, som_partner['address'][0], ['street', 'zip', 'city'])
Expand All @@ -82,7 +44,6 @@ def generationkwh_amortization_data(self, cursor, uid, ids):
else:
report.address_email = None

partner_id = Soci.read(cursor, uid, member_id, ['partner_id'])['partner_id'][0]
partner = ResPartner.read(cursor, uid, partner_id, ['vat', 'name', 'lang'])
report.data_inici = date(report.year, 1, 1).isoformat()
report.data_fi = date(report.year, 12, 31).isoformat()
Expand Down Expand Up @@ -116,7 +77,7 @@ def generationkwh_amortization_data(self, cursor, uid, ids):

return report

GenerationkwhInvestment()
ResPartner()


class RetencionsSobreRendimentGenerationKwh():
Expand Down
1 change: 1 addition & 0 deletions som_generationkwh/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ yamlns
plantmeter
python-dateutil
freezegun
certifi==2021.10.8
2 changes: 0 additions & 2 deletions som_generationkwh/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
"access_wizard_aeat193_from_gkwh_invoices_u","wizard.aeat193.from.gkwh.invoices","model_wizard_aeat193_from_gkwh_invoices","som_generationkwh.group_som_generationkwh_u",1,1,1,1
"access_wizard_aeat193_from_gkwh_invoices_r","wizard.aeat193.from.gkwh.invoices","model_wizard_aeat193_from_gkwh_invoices","som_generationkwh.group_som_generationkwh_r",1,0,0,0
"access_wizard_aeat193_from_gkwh_invoices_w","wizard.aeat193.from.gkwh.invoices","model_wizard_aeat193_from_gkwh_invoices","som_generationkwh.group_som_generationkwh_w",1,1,1,0
"access_send_retencio_estalvi_to_members_wizard_rcwd","send.retencio.estalvi.to.members.wizard","model_send_retencio_estalvi_to_members_wizard","base.group_erp_manager",1,1,1,1
"access_send_retencio_estalvi_to_members_wizard_rcwd","send.retencio.estalvi.to.members.wizard","model_send_retencio_estalvi_to_members_wizard","base.group_system",1,1,1,1
"access_wizard_baixa_soci_rcwd","wizard.baixa.soci","model_wizard_baixa_soci","base.group_partner_manager",1,1,1,1
"access_wizard_generationkwh_sign_signaturit_rcwd","wizard.generationkwh.sign.signaturit","model_wizard_generationkwh_sign_signaturit","som_generationkwh.group_som_generationkwh_u",1,1,1,1
"access_wizard_llibre_registre_socis_rcwd","wizard.llibre.registre.socis","model_wizard_llibre_registre_socis","base_extended.group_base_extended_u",1,1,1,1
Expand Down
109 changes: 2 additions & 107 deletions som_generationkwh/tests/investment_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,113 +1700,6 @@ def test__pending_amortization_summary__allInvestments(self):
self.assertEqual((4, 120),
self.Investment.pending_amortization_summary(cursor, uid, '2022-11-20'))

def test__send_emails_to_investors_with_savings_in_year__whenNoGenkwhEmission(self):
"""
Check send_emails_to_investors_with_savings_in_year when no emissions for Generationkwh
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

all_emissions = self.Emission.search(cursor, uid, [])
self.Emission.write(cursor, uid, all_emissions, dict(type='apo'))

# year 2020 in order to take effects over genkwh_0002 generationkwh investment
ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)
self.assertEqual(ret_value, 0)

def test__send_emails_to_investors_with_savings_in_year__when_noFirstEffectiveDate(self):
"""
Check send_emails_to_investors_with_savings_in_year no active investments,
not already paid (first_effective_date is False)
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

all_gen_investments = self.Investment.search(cursor, uid, [('emission_id.type', '=', 'genkwh')])
self.Investment.write(cursor, uid, all_gen_investments, dict(first_effective_date=False))

ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)
self.assertEqual(ret_value, 0)

def test__send_emails_to_investors_with_savings_in_year__when_invalidFirstEffectiveDate(self):
"""
Check send_emails_to_investors_with_savings_in_year when no active investments,
investments out of active period (first_effective_date over fiscal year used)
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

all_gen_investments = self.Investment.search(cursor, uid, [('emission_id.type', '=', 'genkwh')])
self.Investment.write(cursor, uid, all_gen_investments, dict(first_effective_date='01-01-2021'))

ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)
self.assertEqual(ret_value, 0)

def test__send_emails_to_investors_with_savings_in_year__when_oneMember(self):
"""
Check send_emails_to_investors_with_savings_in_year when one member one emission
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

investments = self.Investment.search(cursor, uid, [('emission_id.type', '=', 'genkwh'),
('first_effective_date', '>=', '2020-01-01'),
('first_effective_date', '<=', '2020-12-31')])
one_valid_investment = investments[0]
investments.remove(one_valid_investment)
self.Investment.write(cursor, uid, investments, dict(first_effective_date=False))

ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)
self.assertEqual(ret_value, 1)

def test__send_emails_to_investors_with_savings_in_year__when_manyInvestmets_sameMember(self):
"""
Check send_emails_to_investors_with_savings_in_year when many investments same member
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

investments = self.Investment.search(cursor, uid, [('emission_id.type', '=', 'genkwh'),
('first_effective_date', '>=', '2020-01-01'),
('first_effective_date', '<=', '2020-12-31')])

member_id = self.Investment.read(cursor, uid, investments[0], ['member_id'])['member_id'][0]
for investment_id in investments:
self.Investment.write(cursor, uid, investments, dict(member_id=member_id))

ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)

self.assertTrue(len(investments) > 1)
self.assertEqual(ret_value, 1)


def test__send_emails_to_investors_with_savings_in_year__when_manyMembers(self):
"""
Check send_emails_to_investors_with_savings_in_year when many members, one investment each
:return:
"""
with Transaction().start(self.database) as txn:
cursor = txn.cursor
uid = txn.user

investments = self.Investment.search(cursor, uid, [('emission_id.type', '=', 'genkwh'),
('first_effective_date', '>=', '2020-01-01'),
('first_effective_date', '<=', '2020-12-31')])

ret_value = self.Soci.send_emails_to_investors_with_savings_in_year(cursor, uid, year=2020)
self.assertEqual(ret_value, len(investments))


def test__get_stats_investment_generation__when_last_effective_date(self):
"""
Check get_stats_investment_generation when some investements with last_effective_date
Expand Down Expand Up @@ -2517,6 +2410,8 @@ def test__generationwkwh_investment_sign__withoutInvoice(self):
with self.assertRaises(except_osv) as ctx:
self.Investment.investment_sign_request(cursor, uid, investment_id)


@unittest.skip("No implemented yet. Keep in mind to mock ResPartnerAddress.write()")
def test__generationwkwh_investment_sign_callback__ok(self):
with Transaction().start(self.database) as txn:
cursor = txn.cursor
Expand Down
1 change: 0 additions & 1 deletion som_generationkwh/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import wizard_investment_divest
import wizard_investment_transfer
import wizard_aeat193_from_gkwh_invoices
import wizard_send_retencio_estalvi_to_members
import wizard_baixa_soci
import wizard_contract_sign_signaturit
import wizard_llibre_registre_socis
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ccd7a19

Please sign in to comment.