diff --git a/__init__.py b/__init__.py index 4f1c1b8..380d1c7 100644 --- a/__init__.py +++ b/__init__.py @@ -1,43 +1,39 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -from .case import Case -from .customer_service import (CustomerService, CustomerServiceReport, - CustomerServiceIndicatorsStart, CustomerServiceIndicators, - CustomerServiceIndicatorsReport, EfficacyMonthStart, EfficacyMonth, - EfficacyMonthReport, MonitoringReport, PrintCustomerService) -from .configuration import Configuration -from .party import Party -from .survey import (SurveyTemplate, Survey, SurveyLine, - SurveyTemplateLine, SurveyGroup, SurveyReport) -from .activity import Activity +from . import case +from . import customer_service +from . import configuration +from . import party +from . import survey +from . import activity def register(): Pool.register( - SurveyGroup, - SurveyTemplate, - SurveyTemplateLine, - Survey, - SurveyLine, - Configuration, - Case, - CustomerService, - CustomerServiceIndicatorsStart, - EfficacyMonthStart, - Party, - Activity, + survey.SurveyGroup, + survey.urveyTemplate, + survey.SurveyTemplateLine, + survey.Survey, + survey.SurveyLine, + configuration.Configuration, + case.Case, + customer_service.CustomerService, + customer_service.CustomerServiceIndicatorsStart, + customer_service.EfficacyMonthStart, + party.Party, + activity.Activity, module='crm', type_='model') Pool.register( - CustomerServiceReport, - CustomerServiceIndicators, - EfficacyMonth, - PrintCustomerService, + customer_service.CustomerServiceReport, + customer_service.CustomerServiceIndicators, + customer_service.EfficacyMonth, + customer_service.PrintCustomerService, module='crm', type_='wizard') Pool.register( - CustomerServiceReport, - CustomerServiceIndicatorsReport, - EfficacyMonthReport, - MonitoringReport, - SurveyReport, + customer_service.CustomerServiceReport, + customer_service.CustomerServiceIndicatorsReport, + customer_service.EfficacyMonthReport, + customer_service.MonitoringReport, + survey.SurveyReport, module='crm', type_='report') diff --git a/activity.py b/activity.py index 5d94b42..86ee944 100644 --- a/activity.py +++ b/activity.py @@ -6,8 +6,8 @@ from trytond.model import Workflow, ModelView, ModelSQL, fields from trytond.pyson import Eval, If, In, Get from trytond.transaction import Transaction from trytond.pool import Pool - -__all__ = ['Activity'] +from .exceptions import CrmConfigurationError +from i18n import gettext STATES = { 'readonly': (Eval('state') != 'draft'), @@ -31,7 +31,6 @@ class Activity(Workflow, ModelSQL, ModelView): media_info = fields.Char('Media Info', states=STATES) planned_date = fields.Date('Planned Date', states=STATES, required=True) effective_date = fields.Date('Effective Date', states=STATES) - # salesman = fields.Many2One('company.employee', 'Salesman', states=STATES) notes = fields.Text('Notes', states=STATES) company = fields.Many2One('company.company', 'Company', required=True, states=STATES, domain=[ ('id', If(In('company', @@ -44,19 +43,12 @@ class Activity(Workflow, ModelSQL, ModelView): ('cancelled', 'Cancelled'), ], 'State', readonly=True, required=True) state_string = state.translated('state') - # sale = fields.Many2One('sale.sale', 'Sale', states=STATES, - # domain=[('party', '=', Eval('customer'))]) - # next_activity = put here next activity planned for customer @classmethod def __setup__(cls): super(Activity, cls).__setup__() cls._order.insert(0, ('planned_date', 'DESC')) cls._order.insert(1, ('id', 'DESC')) - cls._error_messages.update({ - 'missing_sequence_activity': ('The sequence for ' - 'activity is missing!'), - }) cls._transitions |= set(( ('draft', 'pending'), ('pending', 'done'), @@ -120,10 +112,10 @@ class Activity(Workflow, ModelSQL, ModelView): return pool = Pool() Config = pool.get('crm.configuration') - Sequence = pool.get('ir.sequence') config = Config.get_configuration() if not config.crm_activity_sequence: - self.raise_user_error('missing_sequence_activity') + raise CrmConfigurationError( + gettext('crm.msg_missing_sequence_activity') - seq_id = config.crm_activity_sequence.id - self.write([self], {'number': Sequence.get_id(seq_id)}) + seq = config.crm_activity_sequence.get() + self.write([self], {'number': seq}) diff --git a/case.py b/case.py index a86c47b..10ac433 100644 --- a/case.py +++ b/case.py @@ -2,14 +2,12 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields -__all__ = ['Case'] - class Case(ModelSQL, ModelView): "CRM Case" __name__ = "crm.case" name = fields.Char('Name', required=True, translate=True) - parent = fields.Many2One('crm.case','Parent', select=True) + parent = fields.Many2One('crm.case', 'Parent', select=True) childs = fields.One2Many('crm.case', 'parent', string='Children') @classmethod diff --git a/configuration.py b/configuration.py index 02f5685..afaeb93 100644 --- a/configuration.py +++ b/configuration.py @@ -2,24 +2,26 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, ModelSingleton, fields from trytond.transaction import Transaction - -__all__ = ['Configuration'] +from trytond.pyson import Id class Configuration(ModelSingleton, ModelSQL, ModelView): 'CRM Configuration' __name__ = 'crm.configuration' crm_customer_service_sequence = fields.Many2One('ir.sequence', - 'Customer Service Sequence', required=True, domain=[ - ('code', '=', 'crm.customer_service')]) + 'Customer Service Sequence', required=True, + domain=[('sequence_type', '=', + Id('crm', 'sequence_type_crm')), ]) crm_survey_sequence = fields.Many2One('ir.sequence', - 'Survey Sequence', required=True, domain=[ - ('code', '=', 'crm.customer_service')]) + 'Survey Sequence', required=True, + domain=[('sequence_type', '=', + Id('crm', 'sequence_crm_customer_service'))]) efficay_hour_limit = fields.Integer('Efficay Hour Limit', required=True) crm_activity_sequence = fields.Many2One('ir.sequence', - 'Activity Sequence', required=True, domain=[ - ('code', '=', 'crm.customer_service')]) + 'Activity Sequence', required=True, + domain=[('sequence_type', '=', + Id('crm', 'sequence_crm_activity')]) company = fields.Many2One('company.company', 'Company', required=True) @staticmethod diff --git a/configuration.xml b/configuration.xml index 035161a..f2d356d 100644 --- a/configuration.xml +++ b/configuration.xml @@ -37,7 +37,6 @@ this repository contains the full copyright notices and license terms. --> Customer Service - crm.customer_service @@ -51,28 +50,10 @@ this repository contains the full copyright notices and license terms. --> Customer Service - crm.customer_service - CRM Activity - crm.customer_service diff --git a/crm.xml b/crm.xml index 3a52dce..3c8b9fd 100644 --- a/crm.xml +++ b/crm.xml @@ -33,7 +33,7 @@ this repository contains the full copyright notices and license terms. --> icons/tryton-crm.svg - diff --git a/customer_service.py b/customer_service.py index 4008113..87ee80c 100644 --- a/customer_service.py +++ b/customer_service.py @@ -9,11 +9,8 @@ from trytond.transaction import Transaction from trytond.pool import Pool from trytond.wizard import Wizard, StateView, Button, StateReport, StateTransition from trytond.report import Report - -__all__ = ['CustomerService', 'CustomerServiceReport', - 'CustomerServiceIndicatorsStart', 'CustomerServiceIndicators', - 'CustomerServiceIndicatorsReport', 'EfficacyMonthStart', 'EfficacyMonth', - 'EfficacyMonthReport', 'MonitoringReport', 'PrintCustomerService'] +from .exceptions import CustomerServiceError, CrmConfigurationError +from i18n import gettext STATES = { 'readonly': (Eval('state') != 'draft'), @@ -107,14 +104,6 @@ class CustomerService(Workflow, ModelSQL, ModelView): super(CustomerService, cls).__setup__() cls._order.insert(0, ('create_date', 'DESC')) cls._order.insert(1, ('id', 'DESC')) - cls._error_messages.update({ - 'missing_sequence_customer_service': ('The sequence for ' - 'customer service is missing!'), - 'missing_configuration_limit_hour': ('The configuration ' - 'is missing for limit hours!'), - 'delete_numbered': ('The numbered service "%s" can not be ' - 'deleted.'), - }) cls._transitions |= set(( ('draft', 'open'), ('open', 'draft'), @@ -185,7 +174,9 @@ class CustomerService(Workflow, ModelSQL, ModelView): def delete(cls, records): for record in records: if record.number: - cls.raise_user_error('delete_numbered', (record.number,)) + raise CustomerServiceError( + gettext('crm.msg_delete_numbered', s=record.number) + ) super(CustomerService, cls).delete(records) @fields.depends('party', 'address', 'phone') @@ -202,7 +193,8 @@ class CustomerService(Workflow, ModelSQL, ModelView): config = pool.get('crm.configuration')(1) now = datetime.now() if not config.efficay_hour_limit: - self.raise_user_error('missing_configuration_limit_hour') + raise CrmConfigurationError( + gettext('crm.msg_missing_configuration_limit_hour')) val_hr = config.efficay_hour_limit if self.effective_date: lapse = self.effective_date - self.create_date @@ -220,12 +212,11 @@ class CustomerService(Workflow, ModelSQL, ModelView): ''' pool = Pool() config = pool.get('crm.configuration')(1) - Sequence = pool.get('ir.sequence') if not config.crm_customer_service_sequence: - self.raise_user_error('missing_sequence_customer_service') - - seq_id = config.crm_customer_service_sequence.id - self.write([self], {'number': Sequence.get_id(seq_id)}) + raise CrmConfigurationError( + gettext('crm.msg_missing_sequence_customer_service')) + seq = config.crm_customer_service_sequence.get() + self.write([self], {'number': seq}) class PrintCustomerService(Wizard): @@ -249,7 +240,6 @@ class PrintCustomerService(Wizard): except: action['email'] = {} if service and service.party.email: - print('No debe ejecutarse') action['email'].update({"to": service.party.email}) return action, data @@ -263,8 +253,8 @@ class CustomerServiceReport(Report): __name__ = 'crm.customer_service' @classmethod - def get_context(cls, records, data): - report_context = super(CustomerServiceReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) Company = Pool().get('company.company') report_context['company'] = Company(Transaction().context.get('company')) return report_context @@ -289,7 +279,7 @@ class CustomerServiceIndicatorsStart(ModelView): def default_fiscalyear(): FiscalYear = Pool().get('account.fiscalyear') return FiscalYear.find( - Transaction().context.get('company'), exception=False) + Transaction().context.get('company'), exception=False) class CustomerServiceIndicators(Wizard): @@ -323,8 +313,8 @@ class CustomerServiceIndicatorsReport(Report): __name__ = 'crm.customer_service_indicators_report' @classmethod - def get_context(cls, records, data): - report_context = super(CustomerServiceIndicatorsReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Company = pool.get('company.company') Fiscalyear = pool.get('account.fiscalyear') @@ -446,7 +436,7 @@ class EfficacyMonthReport(Report): def _get_months(): return {'month' + str(i + 1): {'num_req': 0, 'efficacy': 0, 'rate': None} - for i in range(12)} + for i in range(12)} total_months = {} @@ -557,8 +547,8 @@ class EfficacyMonthReport(Report): return departments, values @classmethod - def get_context(cls, records, data): - report_context = super(EfficacyMonthReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) pool = Pool() Fiscalyear = pool.get('account.fiscalyear') Company = pool.get('company.company') @@ -578,7 +568,7 @@ class EfficacyMonthReport(Report): services = Service.search(dom_service) departments, values = cls._get_departments(services) - records_months, total_months = cls._get_records_months(services) + records_months, total_months = cls._get_records_months(services) report_context.update(values) report_context.update(total_months) @@ -595,8 +585,8 @@ class MonitoringReport(Report): __name__ = 'crm.monitoring_report' @classmethod - def get_context(cls, records, data): - report_context = super(MonitoringReport, cls).get_context(records, data) + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) user = Pool().get('res.user')(Transaction().user) report_context['company'] = user.company return report_context diff --git a/customer_service.xml b/customer_service.xml index f4d9ec0..6d7e818 100644 --- a/customer_service.xml +++ b/customer_service.xml @@ -71,7 +71,7 @@ this repository contains the full copyright notices and license terms. --> - diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000..a3a804b --- /dev/null +++ b/exceptions.py @@ -0,0 +1,13 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +from trytond.model.exceptions import ValidationError +from trytond.exceptions import UserError, UserWarning + + +class CrmConfigurationError(UserError): + pass + + +class CustomerServiceError(ValidationError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..253b80f --- /dev/null +++ b/message.xml @@ -0,0 +1,23 @@ + + + + + + The sequence for activity is missing! + + + The sequence for customer service is missing! + + + The sequence for survey is missing! + + + The configuration is missing for limit hours! + + + The numbered service "%s" can not be deleted. + + + + diff --git a/party.py b/party.py index e7349d3..02b46e9 100644 --- a/party.py +++ b/party.py @@ -4,8 +4,6 @@ from trytond.model import fields, ModelView from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval -__all__ = ['Party'] - # Size photo default WIDTH = 200 HEIGHT = 250 diff --git a/survey.py b/survey.py index 977dfd4..576e0f4 100644 --- a/survey.py +++ b/survey.py @@ -7,11 +7,6 @@ from trytond.pyson import Eval, If, In, Get from trytond.pool import Pool from trytond.transaction import Transaction -__all__ = ['SurveyTemplate', 'SurveyTemplateLine', - 'Survey', 'SurveyLine', 'SurveyGroup', - 'SurveyReport'] - - STATES = {'readonly': (Eval('state') != 'draft')} RESPONSE = { @@ -169,7 +164,6 @@ class Survey(Workflow, ModelSQL, ModelView): Fill the number field with the survey sequence ''' pool = Pool() - Sequence = pool.get('ir.sequence') Config = pool.get('crm.configuration') config = Config(1) @@ -177,8 +171,9 @@ class Survey(Workflow, ModelSQL, ModelView): if record.number: continue if not config.crm_survey_sequence: - continue - number = Sequence.get_id(config.crm_survey_sequence.id) + raise CrmConfigurationError( + gettext('crm.msg_missing_sequence_survey') + number = config.crm_survey_sequence.get() cls.write([record], {'number': number}) diff --git a/tryton.cfg b/tryton.cfg index 00b1fab..42af418 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=5.0.2 +version=6.0.0 depends: party company_department