Skip to content

Commit

Permalink
Merge 37d660b into 7e23aff
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomacr committed Jul 3, 2019
2 parents 7e23aff + 37d660b commit 0006ae8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion public_budget/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
'name': 'Public Budget',
'license': 'AGPL-3',
'version': '11.0.1.21.0',
'version': '11.0.1.22.0',
'author': 'ADHOC SA,Odoo Community Association (OCA)',
'website': 'www.adhoc.com.ar',
'category': 'Accounting & Finance',
Expand Down
12 changes: 6 additions & 6 deletions public_budget/models/account_payment_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ def unlink(self):
@api.multi
def confirm(self):
for rec in self:
if rec.expedient_id and not rec.expedient_id.\
check_location_allowed_for_current_user():
raise UserError(_('It is not possible'
' to confirm a payment if the payment'
' expedient is not in a users'
' allowed location'))
msg = _('It is not possible'
' to confirm a payment if the payment'
' expedient is not in a users'
' allowed location')
rec.expedient_id and rec.expedient_id.\
check_location_allowed_for_current_user(msg)

if not rec.payment_base_date:
raise ValidationError(_(
Expand Down
34 changes: 22 additions & 12 deletions public_budget/models/expedient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PublicBudgetExpedient(models.Model):
issue_date = fields.Datetime(
readonly=True,
required=True,
default=fields.Datetime.now
default=fields.Datetime.now,
copy=False,
)
cover = fields.Char(
compute='_compute_cover',
Expand Down Expand Up @@ -217,14 +218,16 @@ def check_subsidy_recipient_doc(self):

@api.multi
def write(self, vals):
if not 'message_follower_ids' in vals:
self.check_location_allowed_for_current_user()
if 'pages' in vals:
new_pages = vals.get('pages')
for record in self:
if new_pages < record.pages:
raise ValidationError(_('No puede disminuir la cantidad '
'de páginas de un '
'expediente'))
return super(PublicBudgetExpedient, self).write(vals)
return super().write(vals)

@api.multi
def check_expedients_exist(self):
Expand Down Expand Up @@ -314,18 +317,25 @@ def create(self, vals):
'ir.sequence'].with_context(
ir_sequence_date=vals.get('issue_date')).next_by_code(
'public_budget.expedient') or '/'
return super(PublicBudgetExpedient, self).create(vals)
rec = super(PublicBudgetExpedient, self).create(vals)
rec.check_location_allowed_for_current_user()
return rec

@api.multi
def check_location_allowed_for_current_user(self):
def check_location_allowed_for_current_user(self, msg=None):
"""This method Validate if the current user it's belongs
to the users allowed in the current location of this expedient
"""
self.ensure_one()
if not self.current_location_id or\
not self.current_location_id.user_ids:
return True
if self.env.user.id not in self.current_location_id.user_ids.ids:
return False
else:
return True
for rec in self.filtered(
lambda x: x.current_location_id
and x.current_location_id.user_ids and
x.env.user not in x.current_location_id.user_ids):
raise ValidationError(msg or _(
'Can not complete this operation because the location the '
'expedient is not on your assinged locations'))
return True

@api.multi
def unlink(self):
self.check_location_allowed_for_current_user()
return super().unlink()
16 changes: 8 additions & 8 deletions public_budget/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ def _compute_advance_amounts(self):
@api.multi
def mass_payment_group_create(self):
self.ensure_one()
if not self.expedient_id.check_location_allowed_for_current_user():
raise UserError(_(
"It is not possible to generate a payment order if the "
"expedient of the transaction is not in a permitted location"))
msg = _(
"It is not possible to generate a payment order if the "
"expedient of the transaction is not in a permitted location")
self.expedient_id.check_location_allowed_for_current_user(msg)
self = self.with_context(transaction_id=self.id)
for invoice in self.invoice_ids.filtered(
lambda r: r.state == 'open'):
Expand Down Expand Up @@ -602,10 +602,10 @@ def action_new_payment_group(self):
We dont use action on view because it will open on tree view
'''
self.ensure_one()
if not self.expedient_id.check_location_allowed_for_current_user():
raise UserError(_(
"It is not possible to generate a payment order if the "
"expedient of the transaction is not in a permitted location"))
msg = _(
"It is not possible to generate a payment order if the "
"expedient of the transaction is not in a permitted location")
self.expedient_id.check_location_allowed_for_current_user(msg)
action = self.env['ir.model.data'].xmlid_to_object(
'account_payment_group.action_account_payments_group_payable')

Expand Down
8 changes: 0 additions & 8 deletions public_budget/security/public_budget_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
<field eval="False" name="perm_unlink"/>
</record>

<record id="expedient_in_user_locations_rule" model="ir.rule">
<field name="name">Expedient only in user locations</field>
<field name="model_id" ref="public_budget.model_public_budget_expedient"/>
<field eval="True" name="global"/>
<field eval="False" name="perm_read"/>
<field name="domain_force">['|' ,('current_location_id', 'in', user.location_ids.ids), ('current_location_id', '=', False)]</field>
</record>

<!-- portal expedient users can access all partners, we revert original portal group rule -->
<record model="ir.rule" id="res_partner_portal_expedient_rule">
<field name="name">res_partner: portal expedient</field>
Expand Down
10 changes: 5 additions & 5 deletions public_budget/wizards/transaction_definitive_make_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ def _compute_lines(self):
@api.multi
def make_invoices(self):
self.ensure_one()
if not self.transaction_id.expedient_id\
.check_location_allowed_for_current_user():
raise UserError(_('It is not possible to generate an invoice if '
'the expedient of the transaction is not in a'
' permitted location of its user'))
msg = _('It is not possible to generate an invoice if '
'the expedient of the transaction is not in a'
' permitted location of its user')
self.transaction_id.expedient_id\
.check_location_allowed_for_current_user(msg)
tran_type = self.transaction_id.type_id
advance_account = False
if self.to_invoice_amount < 0.0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def _get_default_company(self):
@api.multi
def confirm(self):
self.ensure_one()
if not self.transaction_id.expedient_id\
.check_location_allowed_for_current_user():
raise UserError(_('It is not possible to generate an invoice if '
'the expedient of the transaction is not in a'
' permitted location of its user'))
msg = _('It is not possible to generate an invoice if '
'the expedient of the transaction is not in a'
' permitted location of its user')
self.transaction_id.expedient_id\
.check_location_allowed_for_current_user(msg)
tran_type = self.transaction_id.type_id
advance_account = False
if tran_type.with_advance_payment:
Expand Down

0 comments on commit 0006ae8

Please sign in to comment.