Skip to content

Commit

Permalink
spaces recurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
brendaf committed Apr 23, 2024
1 parent 3d120f1 commit f09d34d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
102 changes: 53 additions & 49 deletions donation_recurrency/models/donation_recurrency.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from odoo import models, fields, _, api
from odoo import _, api, fields, models

# , Command
# from odoo.osv import expression
from odoo.exceptions import UserError

# , ValidationError
from lxml import etree
# from lxml import etree


class DonationRecurrency(models.Model):
_name = 'donation.recurrency'
_name = "donation.recurrency"
_description = "Donation Recurrency"
# _order = "code, name asc"
_inherit = [
Expand All @@ -18,14 +20,18 @@ class DonationRecurrency(models.Model):
]

@api.model
def _get_view(self, view_id=None, view_type='form', **options):
def _get_view(self, view_id=None, view_type="form", **options):

arch, view = super(DonationRecurrency, self)._get_view(view_id, view_type, **options)
if view_type == 'form' and not self.env.user.has_group('base.group_erp_manager'):
arch, view = super(DonationRecurrency, self)._get_view(
view_id, view_type, **options
)
if view_type == "form" and not self.env.user.has_group(
"base.group_erp_manager"
):
print("Is terminated ", self.is_terminated)
print("Recurring next date ", self.recurring_next_date)
for node in arch.xpath("//field[@name='recurring_next_date']"):
node.set('readonly', '1')
node.set("readonly", "1")
# if view_type == 'form' and self.is_terminated:
# print(self.recurring_next_date)
# for node in arch.xpath("//button[@name='recurring_create_donations']"):
Expand Down Expand Up @@ -53,7 +59,7 @@ def _get_view(self, view_id=None, view_type='form', **options):
# states={"draft": [("readonly", False)]},
)
currency_id = fields.Many2one(
comodel_name='res.currency',
comodel_name="res.currency",
default=lambda self: self.env.company.currency_id,
)
partner_id = fields.Many2one(
Expand Down Expand Up @@ -148,11 +154,13 @@ def _get_view(self, view_id=None, view_type='form', **options):
)

_sql_constraints = [
('no_delete', 'CHECK(active = TRUE)', 'No se permite eliminar registros, solo archivarlos.')
(
"no_delete",
"CHECK(active = TRUE)",
"No se permite eliminar registros, solo archivarlos.",
)
]



def _prepare_value_for_stop(self, date_end):
self.ensure_one()
return {
Expand All @@ -167,7 +175,7 @@ def _prepare_value_for_stop(self, date_end):
),
}

@api.onchange('partner_id')
@api.onchange("partner_id")
def _payment_mode_id(self):
self.payment_mode_id = self.partner_id.customer_payment_mode_id

Expand All @@ -184,9 +192,7 @@ def stop(self, date_end, manual_renew_needed=False, post_message=True):
else:
if not rec.date_end or rec.date_end > date_end:
old_date_end = rec.date_end
rec.write(
rec._prepare_value_for_stop(date_end)
)
rec.write(rec._prepare_value_for_stop(date_end))
if post_message:
msg = (
_(
Expand Down Expand Up @@ -276,18 +282,15 @@ def _get_lines_to_donation(self, date_ref):
lines_donations = []
if not self.line_ids:
raise UserError(
_(
"Cannot create recurrence %s because it doesn't "
"have any lines!"
)
_("Cannot create recurrence %s because it doesn't " "have any lines!")
% self.display_name
)
for line in self.line_ids:
vals = {
'product_id': line.product_id.id,
'quantity': line.quantity,
'unit_price': round(line.unit_price, 2),
'currency_id': self.env.company.currency_id.id
"product_id": line.product_id.id,
"quantity": line.quantity,
"unit_price": round(line.unit_price, 2),
"currency_id": self.env.company.currency_id.id,
}
lines_donations.append(self.env["donation.line"].sudo().create(vals).id)
return sorted(lines_donations)
Expand All @@ -300,15 +303,15 @@ def _prepare_donation(self, date_donation):
self.ensure_one()

vals = {
'partner_id': self.partner_id.id,
'payment_mode_id': self.payment_mode_id.id,
'company_id': self.company_id.id,
'campaign_id': self.campaign_id.id,
'tax_receipt_option': 'annual',
'thanks_template_id': self.thanks_template_id.id,
'line_ids': [],
'donation_date': date_donation,
'contract_id': self.id
"partner_id": self.partner_id.id,
"payment_mode_id": self.payment_mode_id.id,
"company_id": self.company_id.id,
"campaign_id": self.campaign_id.id,
"tax_receipt_option": "annual",
"thanks_template_id": self.thanks_template_id.id,
"line_ids": [],
"donation_date": date_donation,
"contract_id": self.id,
}

return vals
Expand Down Expand Up @@ -342,9 +345,7 @@ def _prepare_recurring_donations_values(self, date_ref_don=False):
continue
donation_vals = contract._prepare_donation(date_ref)
donation_vals["line_ids"] = [(6, 0, donation_lines)]
donations_values.append(
donation_vals
)
donations_values.append(donation_vals)
contract._update_recurring_next_date()
return donations_values

Expand All @@ -360,17 +361,14 @@ def recurring_create_donation(self):

def _get_related_donations(self):
self.ensure_one()
donations = (
self.env["donation.donation"]
.search(
[
(
"contract_id",
"in",
self.ids,
)
]
)
donations = self.env["donation.donation"].search(
[
(
"contract_id",
"in",
self.ids,
)
]
)
return donations

Expand Down Expand Up @@ -455,7 +453,11 @@ def cron_recurring_create_donation(self, date_ref=None):
def recurring_create_donations(self):
for rec in self:
continue_while = True
while rec.recurring_next_date and (not rec.date_end or rec.recurring_next_date <= rec.date_end) and continue_while:
while (
rec.recurring_next_date
and (not rec.date_end or rec.recurring_next_date <= rec.date_end)
and continue_while
):
continue_while = rec.recurring_create_donation()
# if rec.date_end and rec.recurring_next_date:
# continue_while = rec.recurring_next_date <= rec.date_end
Expand All @@ -470,8 +472,10 @@ class DonationRecurrencyLine(models.Model):
_name = "donation.recurrency.line"
_description = "Donation REC Lines"
_rec_name = "product_id"
_inherit = ["donation.line",
"donation.recurrency.mixin",]
_inherit = [
"donation.line",
"donation.recurrency.mixin",
]
_description = "Donation Recurrency Lines"

donation_id = fields.Many2one(
Expand Down
2 changes: 1 addition & 1 deletion donation_recurrency/models/donation_recurrency_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dateutil.relativedelta import relativedelta

from odoo import fields, models, api
from odoo import api, fields, models
# from odoo import api, fields, models


Expand Down
2 changes: 1 addition & 1 deletion donation_recurrency/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ access_donation_recurrency,donation.recurrency,model_donation_recurrency,base.gr
access_donation_recurrency_line,donation.recurrency.line,model_donation_recurrency_line,base.group_user,1,1,1,1
access_donation_donation_rec,donation.donation,donation.model_donation_donation,base.group_user,1,1,1,1
access_donation_terminate_reason,donation.terminate.reason,model_donation_terminate_reason,base.group_user,1,1,1,1
access_donation_recurrency_terminate,donation.recurrency.terminate,model_donation_recurrency_terminate,base.group_user,1,1,1,1
access_donation_recurrency_terminate,donation.recurrency.terminate,model_donation_recurrency_terminate,base.group_user,1,1,1,1
9 changes: 2 additions & 7 deletions donation_recurrency/views/donation.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>




<record id="donation_donation_search_inherit" model="ir.ui.view">
<field name="name">donation.donation.search</field>
<field name="model">donation.donation</field>
<field name="inherit_id" ref="donation.donation_search" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="contract_id"/>
<field name="contract_id" />
</field>

</field>
</record>


</odoo>

0 comments on commit f09d34d

Please sign in to comment.