Skip to content

Commit

Permalink
Merge pull request #73 from Som-Energia/IMP_apos_divest
Browse files Browse the repository at this point in the history
  • Loading branch information
susu105 committed Jan 31, 2022
2 parents 911d053 + 68669e1 commit ad7bb0a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
10 changes: 5 additions & 5 deletions som_generationkwh/investment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,15 @@ def get_or_create_payment_mandate(self, cursor, uid, partner_id, iban, purpose,
}
return PaymentMandate.create(cursor, uid, vals)

def get_or_create_open_payment_order(self, cursor, uid, mode_name, use_invoice = False):
def get_or_create_open_payment_order(self, cursor, uid, payment_mode_name, use_invoice = False):
"""
Searches an existing payment order (remesa)
with the proper payment mode and still in draft.
If none is found, a new one gets created.
"""
PaymentMode = self.pool.get('payment.mode')
payment_mode_ids = PaymentMode.search(cursor, uid, [
('name', '=', mode_name),
('name', '=', payment_mode_name),
])

if not payment_mode_ids: return False
Expand Down Expand Up @@ -1429,13 +1429,13 @@ def open_invoices(self, cursor, uid, ids):
inv_id, 'invoice_open', cursor)
return openOK

def invoices_to_payment_order(self,cursor,uid,invoice_ids, model_name):
def invoices_to_payment_order(self,cursor,uid,invoice_ids, payment_mode_name):
"""
Add the invoices to the currently open payment order having the
specified model name. If none is open, then creates a new one.
specified payment_mode name. If none is open, then creates a new one.
"""
Invoice = self.pool.get('account.invoice')
order_id = self.get_or_create_open_payment_order(cursor, uid, model_name,
order_id = self.get_or_create_open_payment_order(cursor, uid, payment_mode_name,
True)
Invoice.afegeix_a_remesa(cursor,uid,invoice_ids, order_id)

Expand Down
21 changes: 19 additions & 2 deletions som_generationkwh/investment_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ def get_payment_mode_name(self, cursor, uid):
PaymentMode = self.erp.pool.get('payment.mode')
return PaymentMode.read(cursor, uid, payment_mode_id, ['name'])['name']

def get_divest_payment_mode(self, cursor, uid):
imd_model = self.erp.pool.get('ir.model.data')
payment_mode_id = imd_model.get_object_reference(
cursor, uid, 'som_generationkwh', 'genkwh_amortization_payment_mode'
)[1]
PaymentMode = self.erp.pool.get('payment.mode')
return PaymentMode.read(cursor, uid, payment_mode_id, ['name'])['name']

def get_or_create_investment_account(self, cursor, uid, partner_id):
Partner = self.erp.pool.get('res.partner')
partner = Partner.browse(cursor, uid, partner_id)
Expand Down Expand Up @@ -409,7 +417,7 @@ def divest(self, cursor, uid, id, invoice_ids, errors, date_invoice):

Investment.open_invoices(cursor, uid, [invoice_id])
Investment.invoices_to_payment_order(cursor, uid,
[invoice_id], gkwh.amortizationPaymentMode)
[invoice_id], self.get_divest_payment_mode(cursor, uid))
invoice_ids.append(invoice_id)

#Get moveline id
Expand Down Expand Up @@ -618,6 +626,15 @@ def get_payment_mode_name(self, cursor, uid):
PaymentMode = self.erp.pool.get('payment.mode')
return PaymentMode.read(cursor, uid, payment_mode_id, ['name'])['name']

def get_divest_payment_mode(self, cursor, uid):
imd_model = self.erp.pool.get('ir.model.data')
payment_mode_id = imd_model.get_object_reference(
cursor, uid, 'som_generationkwh', 'apo_divestment_payment_mode'
)[1]
PaymentMode = self.erp.pool.get('payment.mode')
return PaymentMode.read(cursor, uid, payment_mode_id, ['name'])['name']


def get_or_create_investment_account(self, cursor, uid, partner_id):
Partner = self.erp.pool.get('res.partner')
partner = Partner.browse(cursor, uid, partner_id)
Expand Down Expand Up @@ -663,7 +680,7 @@ def divest(self, cursor, uid, id, invoice_ids, errors, date_invoice):

Investment.open_invoices(cursor, uid, [invoice_id])
Investment.invoices_to_payment_order(cursor, uid,
[invoice_id], gkwh.amortizationPaymentMode)
[invoice_id], self.get_divest_payment_mode(cursor, uid))
invoice_ids.append(invoice_id)

#Get moveline id
Expand Down
28 changes: 28 additions & 0 deletions som_generationkwh/som_generationkwh_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,34 @@ ${text_legal}
<field name="partner_id">1</field>
<field name="sepa_creditor_code">ES24000F55091367</field>
</record>
<record id="apo_divestment_payment_mode" model="payment.mode">
<field name="name">RETORN APORTACIONS (Enginyers)</field>
<field name="type" search="[('code', '=', 'RECIBO_CSB')]"/>
<field name="journal" ref="apo_fact_journal"/>
<field name="bank_id" search="[('partner_id', '=', 1)]"/>
<field name="tipo">sepa34</field>
<field name="nombre">Som Energia SCCL</field>
<field name="sufijo">000</field>
<field name="require_bank_account" eval="True"/>
<field name="partner_id">1</field>
<field name="sepa_creditor_code">ES24000F55091367</field>
</record>
<record id="emissio_apo_2021" model="generationkwh.emission">
<field name="name">Aportacions</field>
<field name="code">APO_202110</field>
<field name="start_date">2021-10-21-</field>
<field name="amount_emission">15000000</field>
<field name="state">draft</field>
<field name="type">apo</field>
<field name="grace_period">1</field>
<field name="expiration_years">0</field>
<field name="waiting_days">0</field>
<field name="mandate_name">PRESTEC Aportacions</field>
<field name="journal_id" ref="apo_fact_journal"/>
<field name="investment_product_id" ref="apo_product_ae" />
<field name="investment_payment_mode_id" ref="apo_investment_payment_mode" />
<field name="bridge_account_payments_id" ref="pgc_555000000011" />
</record>
<record id="emissio_apo" model="generationkwh.emission">
<field name="name">Aportacions</field>
<field name="code">APO_202003</field>
Expand Down

0 comments on commit ad7bb0a

Please sign in to comment.