| 1 |
|
| 2 |
|
| 3 |
from odoo import _, api, fields, models |
| 4 |
|
| 5 |
|
| 6 |
class ResConfigSettings(models.TransientModel): |
| 7 |
_inherit = 'res.config.settings' |
| 8 |
|
| 9 |
|
| 10 |
default_invoice_policy = fields.Selection( |
| 11 |
selection=[ |
| 12 |
('order', "Invoice what is ordered"), |
| 13 |
('delivery', "Invoice what is delivered") |
| 14 |
], |
| 15 |
string="Invoicing Policy", |
| 16 |
default='order', |
| 17 |
default_model='product.template') |
| 18 |
|
| 19 |
|
| 20 |
group_auto_done_setting = fields.Boolean( |
| 21 |
string="Lock Confirmed Sales", implied_group='sale.group_auto_done_setting') |
| 22 |
group_discount_per_so_line = fields.Boolean( |
| 23 |
string="Discounts", implied_group='sale.group_discount_per_so_line') |
| 24 |
group_proforma_sales = fields.Boolean( |
| 25 |
string="Pro-Forma Invoice", implied_group='sale.group_proforma_sales', |
| 26 |
help="Allows you to send pro-forma invoice.") |
| 27 |
group_warning_sale = fields.Boolean( |
| 28 |
string="Sale Order Warnings", implied_group='sale.group_warning_sale') |
| 29 |
|
| 30 |
|
| 31 |
automatic_invoice = fields.Boolean( |
| 32 |
string="Automatic Invoice", |
| 33 |
help="The invoice is generated automatically and available in the customer portal when the " |
| 34 |
"transaction is confirmed by the payment provider.\nThe invoice is marked as paid and " |
| 35 |
"the payment is registered in the payment journal defined in the configuration of the " |
| 36 |
"payment provider.\nThis mode is advised if you issue the final invoice at the order " |
| 37 |
"and not after the delivery.", |
| 38 |
config_parameter='sale.automatic_invoice', |
| 39 |
) |
| 40 |
|
| 41 |
invoice_mail_template_id = fields.Many2one( |
| 42 |
comodel_name='mail.template', |
| 43 |
string="Email Template", |
| 44 |
domain=[('model', '=', 'account.move')], |
| 45 |
config_parameter='sale.default_invoice_email_template', |
| 46 |
help="Email sent to the customer once the invoice is available.", |
| 47 |
) |
| 48 |
quotation_validity_days = fields.Integer( |
| 49 |
related='company_id.quotation_validity_days', |
| 50 |
readonly=False) |
| 51 |
portal_confirmation_sign = fields.Boolean( |
| 52 |
related='company_id.portal_confirmation_sign', |
| 53 |
readonly=False) |
| 54 |
portal_confirmation_pay = fields.Boolean( |
| 55 |
related='company_id.portal_confirmation_pay', |
| 56 |
readonly=False) |
| 57 |
prepayment_percent = fields.Float( |
| 58 |
related='company_id.prepayment_percent', |
| 59 |
readonly=False) |
| 60 |
downpayment_account_id = fields.Many2one(related='company_id.downpayment_account_id', readonly=False) |
| 61 |
|
| 62 |
|
| 63 |
module_delivery = fields.Boolean("Delivery Methods") |
| 64 |
module_delivery_bpost = fields.Boolean("bpost Connector") |
| 65 |
module_delivery_dhl = fields.Boolean("DHL Express Connector") |
| 66 |
module_delivery_easypost = fields.Boolean("Easypost Connector") |
| 67 |
module_delivery_envia = fields.Boolean("Envia.com Connector") |
| 68 |
module_delivery_fedex_rest = fields.Boolean("FedEx Connector") |
| 69 |
module_delivery_sendcloud = fields.Boolean("Sendcloud Connector") |
| 70 |
module_delivery_shiprocket = fields.Boolean("Shiprocket Connector") |
| 71 |
module_delivery_starshipit = fields.Boolean("Starshipit Connector") |
| 72 |
module_delivery_ups_rest = fields.Boolean("UPS Connector") |
| 73 |
module_delivery_usps_rest = fields.Boolean("USPS Connector") |
| 74 |
|
| 75 |
module_product_email_template = fields.Boolean("Specific Email") |
| 76 |
module_sale_amazon = fields.Boolean("Amazon Sync") |
| 77 |
module_sale_commission = fields.Boolean("Commissions") |
| 78 |
module_sale_gelato = fields.Boolean("Gelato") |
| 79 |
module_sale_loyalty = fields.Boolean("Coupons & Loyalty") |
| 80 |
module_sale_margin = fields.Boolean("Margins") |
| 81 |
module_sale_pdf_quote_builder = fields.Boolean("PDF Quote builder") |
| 82 |
module_sale_product_matrix = fields.Boolean("Sales Grid Entry") |
| 83 |
module_sale_shopee = fields.Boolean("Shopee Sync") |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
@api.depends('group_discount_per_so_line') |
| 88 |
def _onchange_group_discount_per_so_line(self): |
| 89 |
if self.group_discount_per_so_line: |
| 90 |
self.group_product_pricelist = True |
| 91 |
|
| 92 |
@api.onchange('group_product_variant') |
| 93 |
def _onchange_group_product_variant(self): |
| 94 |
"""The product Configurator requires the product variants activated. |
| 95 |
If the user disables the product variants -> disable the product configurator as well""" |
| 96 |
if self.module_sale_product_matrix and not self.group_product_variant: |
| 97 |
self.module_sale_product_matrix = False |
| 98 |
|
| 99 |
@api.onchange('portal_confirmation_pay') |
| 100 |
def _onchange_portal_confirmation_pay(self): |
| 101 |
self.prepayment_percent = self.prepayment_percent or 1.0 |
| 102 |
|
| 103 |
@api.onchange('prepayment_percent') |
| 104 |
def _onchange_prepayment_percent(self): |
| 105 |
if not self.prepayment_percent: |
| 106 |
self.portal_confirmation_pay = False |
| 107 |
|
| 108 |
@api.onchange('quotation_validity_days') |
| 109 |
def _onchange_quotation_validity_days(self): |
| 110 |
if self.quotation_validity_days < 0: |
| 111 |
self.quotation_validity_days = self.env['res.company'].default_get( |
| 112 |
['quotation_validity_days'] |
| 113 |
)['quotation_validity_days'] |
| 114 |
return { |
| 115 |
'warning': { |
| 116 |
'title': _("Warning"), |
| 117 |
'message': _("Quotation Validity is required and must be greater or equal to 0."), |
| 118 |
}, |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
def set_values(self): |
| 124 |
super().set_values() |
| 125 |
if self.default_invoice_policy != 'order': |
| 126 |
self.env['ir.config_parameter'].set_param(key='sale.automatic_invoice', value=False) |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
def action_sale_start_payment_onboarding(self): |
| 132 |
menu = self.env.ref('sale.menu_sale_general_settings', raise_if_not_found=False) |
| 133 |
return self._start_payment_onboarding(menu and menu.id) |