[IMP] account, sale: Move terms and conditions to account

Purpose
=======

Be able to define terms and conditions if sales is not installed.

If sales is not installed, the user cannot define default terms and conditions
for his customer invoices since the setting in the sales section.

If sales is installed and default terms & conditions are defined, a customer
invoice created from scratch (not from an SO) will have them.

This is not consistent.

Task: 1917663

closes odoo/odoo#30140
This commit is contained in:
mgh-odoo
2019-02-07 13:11:19 +00:00
committed by Yannick Tivisse
parent f711e6d6a2
commit ca25a692bd
10 changed files with 34 additions and 35 deletions
+6 -1
View File
@@ -97,6 +97,11 @@ class AccountInvoice(models.Model):
journal = self._default_journal()
return journal.currency_id or journal.company_id.currency_id or self.env.user.company_id.currency_id
def _default_comment(self):
invoice_type = self.env.context.get('type', 'out_invoice')
if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms'):
return self.env.user.company_id.invoice_terms
@api.one
@api.depends(
'state', 'currency_id', 'invoice_line_ids.price_subtotal',
@@ -255,7 +260,7 @@ class AccountInvoice(models.Model):
help="Technical field holding the number given to the invoice, automatically set when the invoice is validated then stored to set the same number again if the invoice is cancelled, set to draft and re-validated.")
reference = fields.Char(string='Payment Ref.', copy=False, readonly=True, states={'draft': [('readonly', False)]},
help='The payment communication that will be automatically populated once the invoice validation. You can also write a free communication.')
comment = fields.Text('Additional Information', readonly=True, states={'draft': [('readonly', False)]})
comment = fields.Text('Additional Information', readonly=True, states={'draft': [('readonly', False)]}, default=_default_comment)
state = fields.Selection([
('draft','Draft'),
+1
View File
@@ -104,6 +104,7 @@ Best Regards,'''))
# account dashboard onboarding
account_invoice_onboarding_state = fields.Selection([('not_done', "Not done"), ('just_done', "Just done"), ('done', "Done"), ('closed', "Closed")], string="State of the account invoice onboarding panel", default='not_done')
account_dashboard_onboarding_state = fields.Selection([('not_done', "Not done"), ('just_done', "Just done"), ('done', "Done"), ('closed', "Closed")], string="State of the account dashboard onboarding panel", default='not_done')
invoice_terms = fields.Text(string='Default Terms and Conditions', translate=True)
@api.constrains('account_opening_date', 'fiscalyear_last_day', 'fiscalyear_last_month')
def _check_fiscalyear_last_day(self):
@@ -91,6 +91,11 @@ class ResConfigSettings(models.TransientModel):
invoice_is_print = fields.Boolean(string='Print', related='company_id.invoice_is_print', readonly=False)
invoice_is_email = fields.Boolean(string='Send Email', related='company_id.invoice_is_email', readonly=False)
incoterm_id = fields.Many2one('account.incoterms', string='Default incoterm', related='company_id.incoterm_id', help='International Commercial Terms are a series of predefined commercial terms used in international transactions.', readonly=False)
invoice_terms = fields.Text(related='company_id.invoice_terms', string="Terms & Conditions", readonly=False)
use_invoice_terms = fields.Boolean(
string='Default Terms & Conditions',
oldname='default_use_sale_note',
config_parameter='account.use_invoice_terms')
@api.multi
def set_values(self):
@@ -486,6 +486,23 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="use_invoice_terms"/>
</div>
<div class="o_setting_right_pane">
<label for="use_invoice_terms"/>
<span class="fa fa-lg fa-building-o" title="Values set here are company-specific." aria-label="Values set here are company-specific." groups="base.group_multi_company" role="img"/>
<div class="text-muted">
Show standard terms &amp; conditions on invoices/orders
</div>
<div class="content-group" attrs="{'invisible': [('use_invoice_terms','=',False)]}">
<div class="mt16">
<field name="invoice_terms" placeholder="Insert your terms &amp; conditions here..."/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="group_warning_account"/>
+1 -7
View File
@@ -11,13 +11,7 @@ class AccountInvoice(models.Model):
def _get_default_team(self):
return self.env['crm.team']._get_default_team_id()
def _default_comment(self):
invoice_type = self.env.context.get('type', 'out_invoice')
if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('sale.use_sale_note'):
return self.env.user.company_id.sale_note
team_id = fields.Many2one('crm.team', string='Sales Team', default=_get_default_team, oldname='section_id')
comment = fields.Text(default=_default_comment)
partner_shipping_id = fields.Many2one(
'res.partner',
string='Delivery Address',
@@ -48,7 +42,7 @@ class AccountInvoice(models.Model):
self.partner_shipping_id = addr and addr.get('delivery')
if self.env.context.get('type', 'out_invoice') == 'out_invoice':
company = self.company_id or self.env.user.company_id
self.comment = company.with_context(lang=self.partner_id.lang).sale_note
self.comment = company.with_context(lang=self.partner_id.lang).invoice_terms
@api.multi
def action_invoice_open(self):
-1
View File
@@ -7,7 +7,6 @@ from odoo import api, fields, models, _
class ResCompany(models.Model):
_inherit = "res.company"
sale_note = fields.Text(string='Default Terms and Conditions', translate=True)
portal_confirmation_sign = fields.Boolean(string='Online Signature')
portal_confirmation_pay = fields.Boolean(string='Online Payment')
quotation_validity_days = fields.Integer(default=30, string="Default Quotation Validity (Days)")
@@ -7,11 +7,6 @@ from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
sale_note = fields.Text(related='company_id.sale_note', string="Terms & Conditions", readonly=False)
use_sale_note = fields.Boolean(
string='Default Terms & Conditions',
oldname='default_use_sale_note',
config_parameter='sale.use_sale_note')
group_discount_per_so_line = fields.Boolean("Discounts", implied_group='sale.group_discount_per_so_line')
module_sale_margin = fields.Boolean("Margins")
quotation_validity_days = fields.Integer(related='company_id.quotation_validity_days', string="Default Quotation Validity (Days)", readonly=False)
+3 -3
View File
@@ -101,7 +101,7 @@ class SaleOrder(models.Model):
@api.model
def _default_note(self):
return self.env['ir.config_parameter'].sudo().get_param('sale.use_sale_note') and self.env.user.company_id.sale_note or ''
return self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.user.company_id.invoice_terms or ''
@api.model
def _get_default_team(self):
@@ -306,8 +306,8 @@ class SaleOrder(models.Model):
'partner_shipping_id': addr['delivery'],
'user_id': self.partner_id.user_id.id or self.env.uid
}
if self.env['ir.config_parameter'].sudo().get_param('sale.use_sale_note') and self.env.user.company_id.sale_note:
values['note'] = self.with_context(lang=self.partner_id.lang).env.user.company_id.sale_note
if self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.user.company_id.invoice_terms:
values['note'] = self.with_context(lang=self.partner_id.lang).env.user.company_id.invoice_terms
# Use team of saleman before to fallback on team of partner.
values['team_id'] = self.partner_id.user_id and self.partner_id.user_id.sale_team_id.id or self.partner_id.team_id.id
@@ -177,23 +177,6 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="use_sale_note"/>
</div>
<div class="o_setting_right_pane">
<label for="use_sale_note"/>
<span class="fa fa-lg fa-building-o" title="Values set here are company-specific." aria-label="Values set here are company-specific." groups="base.group_multi_company" role="img"/>
<div class="text-muted">
Show standard terms &amp; conditions on orders
</div>
<div class="content-group" attrs="{'invisible': [('use_sale_note','=',False)]}">
<div class="mt16">
<field name="sale_note" placeholder="Insert your terms &amp; conditions here..."/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="use_quotation_validity_days"/>
+1 -1
View File
@@ -1695,7 +1695,7 @@
<div class="container">
<div class="row">
<div class="col-lg-12 mb16 mt16">
<p style='white-space:pre' t-esc="website.company_id.sale_note"/>
<p style='white-space:pre' t-esc="website.company_id.invoice_terms"/>
</div>
</div>
</div>