Skip to content

Commit

Permalink
[ADD] p13n_cmr: sipreco_subsidies
Browse files Browse the repository at this point in the history
  • Loading branch information
mav-adhoc committed Sep 12, 2023
1 parent 51c840f commit 8e3086a
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public_budget/views/expedient_views.xml
Expand Up @@ -74,7 +74,7 @@
<field name="final_location" states="closed,annulled"/>
<field name="pages"/>
<field name="parliamentary_expedient"/>
<field name="subsidy_expedient"/>
<field name="subsidy_expedient" invisible="1"/>
<field name="subsidy_recipient_doc" attrs="{'invisible': [('subsidy_expedient', '!=', True)]}" />
<field name="subsidy_amount" attrs="{'invisible': [('subsidy_expedient', '!=', True)]}" />
<field name="subsidy_approved" attrs="{'invisible': [('subsidy_expedient', '!=', True)]}" />
Expand Down
1 change: 1 addition & 0 deletions sipreco_subsidy_management/__init__.py
@@ -1 +1,2 @@
from . import models
from . import wizards
7 changes: 6 additions & 1 deletion sipreco_subsidy_management/__manifest__.py
@@ -1,6 +1,6 @@
{
'name': 'Public Budget Subsidy Management',
'version': "15.0.1.0.0",
'version': "15.0.1.2.0",
'author': 'ADHOC SA,Odoo Community Association (OCA)',
'website': 'www.adhoc.com.ar',
'category': 'Accounting & Finance',
Expand All @@ -13,6 +13,7 @@
'reports/subsidy_report.xml',
'reports/subsidy_report_resolution.xml',
'views/subsidy_views.xml',
'views/subsidy_ticket_views.xml',
'views/transaction_type_views.xml',
'views/subsidy_approval_arrangement_views.xml',
'views/subsidy_note_type_views.xml',
Expand All @@ -21,13 +22,17 @@
'data/sequence_data.xml',
'data/subsidy_note_type_data.xml',
'data/cron.xml',
'data/ir_actions_server_data.xml',
'wizards/create_expedients_wizard_views.xml',
'views/expedient_views.xml'
],
'demo': [
'demo/public_budget.transaction_type.csv',
'demo/subsidy_demo.xml',
],
'depends': [
'public_budget',
'helpdesk'
],
'installable': True,
}
16 changes: 16 additions & 0 deletions sipreco_subsidy_management/data/ir_actions_server_data.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Generar expédientes -->
<record model="ir.actions.server" id="action_generate_expedient">
<field name="name">Generar Expedientes</field>
<field name="model_id" ref="helpdesk.model_helpdesk_ticket"/>
<field name="binding_model_id" ref="helpdesk.model_helpdesk_ticket"/>
<field name="state">code</field>
<field name="code">
action = env["ir.actions.act_window"]._for_xml_id('sipreco_subsidy_management.action_create_expedients_wizard')
helpdesk_tickets = records.filtered(lambda x: x.stage_id.name in ['Ticket', 'Aprobado'])
action['context'] = {'active_ids': helpdesk_tickets.ids}
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions sipreco_subsidy_management/models/__init__.py
Expand Up @@ -5,4 +5,6 @@
from . import subsidy_note_type
from . import subsidy_resolution
from . import subsidy_resolution_line
from . import subsidy_ticket
from . import transaction_type
from . import expedient
18 changes: 18 additions & 0 deletions sipreco_subsidy_management/models/expedient.py
@@ -0,0 +1,18 @@
from odoo import models, fields


class PublicBudgetExpedient(models.Model):

_inherit = 'public_budget.expedient'

purchase_order_ids = fields.One2many(
'helpdesk.ticket',
'expedient_id',
)

def action_open_subsidy_ticket(self):
action = self.env["ir.actions.actions"]._for_xml_id("helpdesk.helpdesk_ticket_action_main_tree")
action['context'] = {}
all_child = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
action['domain'] = [('expedient_id', 'in', self.ids)]
return action
56 changes: 56 additions & 0 deletions sipreco_subsidy_management/models/subsidy_ticket.py
@@ -0,0 +1,56 @@
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
import stdnum

class PublicBudgetSubsidyTicket(models.Model):

_inherit = 'helpdesk.ticket'

dni = fields.Char(
size=8,
string="DNI",
required=True,
)
currency_id = fields.Many2one(
'res.currency',
related='company_id.currency_id',
readonly=True,
)
amount = fields.Monetary(
required=True,
currency_field='currency_id',
)
cbu = fields.Char(
size=22,
string="CBU",
required=True,
)
photo_dni = fields.Binary(
string="Foto DNI",
store=True,
)
expedient_id = fields.Many2one(
"public_budget.expedient",
string="Expediente",
copy=False,

)

@api.constrains('cbu')
def _check_cbu_length(self):
for partner in self:
if partner.cbu and len(partner.cbu) != 22:
raise ValidationError("El CBU debe tener 22 caracteres.")

@api.constrains('dni')
def _check_dni_length(self):
for partner in self:
if partner.dni and len(partner.dni) != 8:
raise ValidationError("El DNI debe tener 8 caracteres.")

# def action_view_ticket(self):
# self.ensure_one()
# action = self.env["ir.actions.act_window"]._for_xml_id(
# 'sipreco_subsidy_management.action_sipreco_subsidy_management_subsidy_tickets')
# action['domain'] = [('id', 'in', self.ticket_ids.ids)]
# return action
1 change: 1 addition & 0 deletions sipreco_subsidy_management/security/ir.model.access.csv
Expand Up @@ -15,3 +15,4 @@ access_public_budget_subsidy_note_type_account_manager,access_public_budget_subs
access_public_budget_subsidy_note_type_all,access_public_budget_subsidy_note_type_all,model_public_budget_subsidy_note_type,,1,0,0,0
access_public_budget_subsidy_resolution_secretary_user,access_public_budget_subsidy_resolution_secretary_user,model_public_budget_subsidy_resolution,public_budget.group_secretary_usuario,1,1,1,1
access_public_budget_subsidy_resolution_line_secretary_user,access_public_budget_subsidy_resolution_line_secretary_user,model_public_budget_subsidy_resolution_line,public_budget.group_secretary_usuario,1,1,1,1
access_public_budget_create_expedients_wizard,access_public_budget_create_expedients_wizard,model_public_budget_create_expedients_wizard,base.group_user,1,1,1,0
19 changes: 19 additions & 0 deletions sipreco_subsidy_management/views/expedient_views.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Add contextual button on partner form view -->
<record id="view_expedients_form" model="ir.ui.view">
<field name="name">public_budget.expedient.form</field>
<field name="model">public_budget.expedient</field>
<field name="inherit_id" ref="public_budget.view_public_budget_expedient_form"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object"
name="action_open_subsidy_ticket" context="{'default_partner_id': active_id}" icon="fa-life-ring">
<div class="o_stat_info">
<span class="o_stat_text"> Subsidies</span>
</div>
</button>
</div>
</field>
</record>
</odoo>
111 changes: 111 additions & 0 deletions sipreco_subsidy_management/views/subsidy_ticket_views.xml
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="subsidy_ticket_view_form" model="ir.ui.view">
<field name="name">subsidy.ticket.form</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_ticket_view_form"/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="dni"/>
<field name="amount" string="Monto" widget="monetary"/>
<field name="cbu"/>
<field name="photo_dni" widget="image" style="margin-top: 25px; margin-bottom: 25px;"/>
<label for="description" string="Motivo"></label>
</field>
<field name="ticket_type_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="tag_ids" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="priority" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="team_id" position="before">
<field name="expedient_id"/>
</field>
</field>
</record>

<record id="subsidy_ticket_view_tree" model="ir.ui.view">
<field name="name">subsidy.ticket.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="after">
<field name="expedient_id"/>
</field>
<field name="partner_id" position="after">
<field name="dni"/>
<field name="amount" string="Monto"/>
</field>
<field name="activity_ids" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="priority" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="sla_deadline" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>

<record id="subsidy_ticket_view_kanban" model="ir.ui.view">
<field name="name">subsidy.ticket.kanban</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_ticket_view_kanban"/>
<field name="arch" type="xml">
<xpath expr="//templates//field[@name='priority']" position="after">
<group>
DNI:
<field name="dni" string="DNI"/>
</group>
<group>
$
<field name="amount" string="Monto" widget="monetary"/>
</group>
</xpath>
<xpath expr="//templates//field[@name='ticket_type_id']" position="after">
<group>
Expediente:
<field name="expedient_id"/>
</group>
</xpath>
<xpath expr="//templates//field[@name='activity_ids']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//templates//field[@name='priority']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//templates//field[@name='sla_deadline']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//templates//field[@name='kanban_state']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//templates//field[@name='user_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

<record id="subsidy_tickets_view_search" model="ir.ui.view">
<field name="name">subsidy.ticket.search</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_search"/>
<field name="arch" type="xml">
<search>
<field name="dni" string="DNI"/>
<field name="cbu" string="CBU"/>
<field name="amount" string="Monto"/>
<field name="expedient_id" string="Expediente"/>
<group expand="0" string="Group By">
<filter string="Expediente" name="expedient_id" context="{'group_by': 'expedient_id'}"/>
</group>
</search>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions sipreco_subsidy_management/wizards/__init__.py
@@ -0,0 +1 @@
from . import create_expedients_wizard
75 changes: 75 additions & 0 deletions sipreco_subsidy_management/wizards/create_expedients_wizard.py
@@ -0,0 +1,75 @@
from odoo import models, fields, api, _, Command
from odoo.exceptions import UserError


class PublicBudgetCreateExepedientsWizard(models.TransientModel):
_name = "public_budget.create.expedients.wizard"
_description = "public_budget.create.expedients.wizard"

reference = fields.Char(
required=False
)
founder_id = fields.Many2one(
'public_budget.expedient_founder',
required=True
)
category_id = fields.Many2one(
'public_budget.expedient_category',
required=True
)
first_location_id = fields.Many2one(
'public_budget.location',
required=True,
)
user_location_ids = fields.Many2many(
'public_budget.location',
'public_budget_create_expedients_location_rel',
default=lambda self: self.env.user.location_ids.ids,
)
pages = fields.Integer(
required=True,
)
helpdesk_ticket_ids = fields.Many2one(
'helpdesk.ticket',
# default=lambda self: self._default_helpdesk_tickets(),
)

# def _default_helpdesk_tickets(self):
# active_tickets_ids = self._context.get('active_ids') or []
# helpdesk_tickets = self.env['helpdesk.ticket'].browse(active_tickets_ids)
# return helpdesk_tickets.ids

def confirm(self):
active_tickets_ids = self._context.get('active_ids') or []
tickets = self.env['helpdesk.ticket'].browse(active_tickets_ids)
if not tickets:
raise UserError(_('It has not approved the ticket/s to generate an expedient'))
if tickets.expedient_id:
raise UserError(_('One of the tickets has already an expedient associated'))
if len(set(tickets.mapped('dni'))) != len(tickets.mapped('dni')):
raise UserError('No puede haber dos tickets con el mismo DNI en el mismo expediente.')
vals = {
'description': tickets[0].name,
'supplier_ids': [Command.set(tickets.partner_id.ids)],
'reference': self.reference,
'founder_id': self.founder_id.id,
'category_id': self.category_id.id,
'first_location_id': self.first_location_id.id,
'pages': self.pages,
}

expedient = self.env['public_budget.expedient'].create(vals)
# we do with sudo because in case that an user to only allow to read PO try to create an expedient
# if came from an requisition.
tickets.write({'expedient_id': expedient.id})
stage = self.env['helpdesk.stage'].search([('name', '=', "Resolucion")], limit=1)
tickets.write({'stage_id': stage.id})

action = self.env["ir.actions.actions"]._for_xml_id(
'public_budget.action_public_budget_expedient_expedients')

if expedient:
res = self.env.ref('public_budget.view_public_budget_expedient_form', False)
action['views'] = [(res and res.id or False, 'form')]
action['res_id'] = expedient.id
return action
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_create_expedients_wizard_form" model="ir.ui.view">
<field name="name">Create Expedients Wizard</field>
<field name="model">public_budget.create.expedients.wizard</field>
<field name="arch" type="xml">
<form string="Asistente de Generacion de Expedientes">
<group>
<field name="reference"/>
<field name="founder_id"/>
</group>
<group>
<field name="category_id"/>
<field name="user_location_ids" invisible="1"/>
<field name="first_location_id" domain="[('id', 'in',user_location_ids)]"/>
<field name="pages"/>
</group>
<footer>
<button name="confirm" string="Confirmar" type="object" class="oe_highlight"/>
o
<button string="Cancelar" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_create_expedients_wizard" model="ir.actions.act_window">
<field name="name">Asistente de creacion de Expedientes</field>
<field name="res_model">public_budget.create.expedients.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

</odoo>

0 comments on commit 8e3086a

Please sign in to comment.