diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index fd96327c23d..f8661ac7e3e 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -464,6 +464,22 @@ class AccountInvoice(models.Model): payment_term_id = p.property_supplier_payment_term_id.id fiscal_position = p.property_account_position_id.id bank_id = p.bank_ids and p.bank_ids.ids[0] or False + + # If partner has no warning, check its company + if p.invoice_warn == 'no-message' and p.parent_id: + p = p.parent_id + if p.invoice_warn != 'no-message': + # Block if partner only has warning but parent company is blocked + if p.invoice_warn != 'block' and p.parent_id and p.parent_id.invoice_warn == 'block': + p = p.parent_id + warning = { + 'title': _("Warning for %s") % p.name, + 'message': p.invoice_warn_msg + } + if p.invoice_warn == 'block': + self.partner_id = False + return {'warning': warning} + self.account_id = account_id self.payment_term_id = payment_term_id self.fiscal_position_id = fiscal_position @@ -471,6 +487,7 @@ class AccountInvoice(models.Model): if type in ('in_invoice', 'in_refund'): self.partner_bank_id = bank_id + @api.onchange('journal_id') def _onchange_journal_id(self): if self.journal_id: diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index b66d15cc165..a7a7301a9a1 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -6,7 +6,7 @@ import time from openerp import api, fields, models, _ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.exceptions import ValidationError - +from openerp.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP class AccountFiscalPosition(models.Model): _name = 'account.fiscal.position' @@ -445,6 +445,8 @@ class ResPartner(models.Model): contract_ids = fields.One2many('account.analytic.account', 'partner_id', string='Contracts', readonly=True) bank_account_count = fields.Integer(compute='_compute_bank_count', string="Bank") trust = fields.Selection([('good', 'Good Debtor'), ('normal', 'Normal Debtor'), ('bad', 'Bad Debtor')], string='Degree of trust you have in this debtor', default='normal', company_dependent=True) + invoice_warn = fields.Selection(WARNING_MESSAGE, 'Invoice', help=WARNING_HELP, required=True, default="no-message") + invoice_warn_msg = fields.Text('Message for Invoice') @api.multi def _compute_bank_count(self): diff --git a/addons/account/views/partner_view.xml b/addons/account/views/partner_view.xml index 5a9ecd067bf..748994dac60 100644 --- a/addons/account/views/partner_view.xml +++ b/addons/account/views/partner_view.xml @@ -119,6 +119,14 @@ + + + + + + + diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 3a85aeccdb1..661e9614e68 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -15,6 +15,16 @@ from odoo.modules import get_module_resource from odoo.osv.expression import get_unaccent_wrapper from odoo.exceptions import UserError, ValidationError +# Global variables used for the warning fields declared on the res.partner +# in the following modules : sale, purchase, account, stock +WARNING_MESSAGE = [ + ('no-message','No Message'), + ('warning','Warning'), + ('block','Blocking Message') + ] +WARNING_HELP = _('Selecting the "Warning" option will notify user with the message, Selecting "Blocking Message" will throw an exception with the message and block the flow. The Message has to be written in the next field.') + + ADDRESS_FORMAT_CLASSES = { '%(city)s %(state_code)s\n%(zip)s': 'o_city_state', '%(zip)s %(city)s': 'o_zip_city' @@ -112,7 +122,6 @@ class PartnerTitle(models.Model): name = fields.Char(string='Title', required=True, translate=True) shortcut = fields.Char(string='Abbreviation', translate=True) - class Partner(models.Model, FormatAddress): _description = 'Partner' _name = "res.partner" diff --git a/openerp/addons/base/res/res_partner_view.xml b/openerp/addons/base/res/res_partner_view.xml index fd3ee9786b7..90126c37746 100644 --- a/openerp/addons/base/res/res_partner_view.xml +++ b/openerp/addons/base/res/res_partner_view.xml @@ -320,6 +320,7 @@ +