| 1 |
from odoo import api, models, fields, _ |
| 2 |
from odoo.exceptions import ValidationError |
| 3 |
from odoo.fields import Domain |
| 4 |
|
| 5 |
|
| 6 |
class ResCompany(models.Model): |
| 7 |
_name = 'res.company' |
| 8 |
_inherit = ['res.company', 'pos.load.mixin'] |
| 9 |
|
| 10 |
point_of_sale_update_stock_quantities = fields.Selection([ |
| 11 |
('closing', 'At the session closing'), |
| 12 |
('real', 'In real time'), |
| 13 |
], default='real', string="Update quantities in stock", |
| 14 |
help="At the session closing: A picking is created for the entire session when it's closed\n In real time: Each order sent to the server create its own picking") |
| 15 |
point_of_sale_use_ticket_qr_code = fields.Boolean( |
| 16 |
string='Self-service invoicing', |
| 17 |
default=True, |
| 18 |
help="Print information on the receipt to allow the customer to easily access the invoice anytime, from Odoo's portal.") |
| 19 |
point_of_sale_ticket_unique_code = fields.Boolean( |
| 20 |
string='Generate a code on ticket', |
| 21 |
help="Add a 5-digit code on the receipt to allow the user to request the invoice for an order on the portal.") |
| 22 |
point_of_sale_ticket_portal_url_display_mode = fields.Selection([ |
| 23 |
('qr_code', 'QR code'), |
| 24 |
('url', 'URL'), |
| 25 |
('qr_code_and_url', 'QR code + URL'), |
| 26 |
], default='qr_code_and_url', |
| 27 |
string='Print', |
| 28 |
help="Choose how the URL to the portal will be print on the receipt.", |
| 29 |
required=True) |
| 30 |
|
| 31 |
@api.model |
| 32 |
def _load_pos_data_domain(self, data, config): |
| 33 |
return [('id', '=', config.company_id.id)] |
| 34 |
|
| 35 |
@api.model |
| 36 |
def _load_pos_data_fields(self, config): |
| 37 |
return [ |
| 38 |
'id', 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id', |
| 39 |
'country_id', 'state_id', 'tax_calculation_rounding_method', 'nomenclature_id', 'point_of_sale_use_ticket_qr_code', |
| 40 |
'point_of_sale_ticket_unique_code', 'point_of_sale_ticket_portal_url_display_mode', 'street', 'city', 'zip', |
| 41 |
'account_fiscal_country_id', |
| 42 |
] |
| 43 |
|
| 44 |
@api.constrains('fiscalyear_lock_date', 'tax_lock_date', 'sale_lock_date', 'hard_lock_date') |
| 45 |
def validate_lock_dates(self): |
| 46 |
""" This constrains makes it impossible to change the relevant lock dates if |
| 47 |
some open POS session would violate them. Without that, these POS sessions |
| 48 |
could not be closed (since the closing entries violate the lock dates). |
| 49 |
""" |
| 50 |
pos_session_model = self.env['pos.session'].sudo() |
| 51 |
for record in self: |
| 52 |
record = record.with_context(ignore_exceptions=True) |
| 53 |
fiscal_lock_date = max(record.user_fiscalyear_lock_date, record.user_hard_lock_date) |
| 54 |
sessions_in_period = pos_session_model.search( |
| 55 |
Domain("company_id", "child_of", record.id) |
| 56 |
& Domain("state", "!=", "closed") |
| 57 |
& Domain.OR(( |
| 58 |
Domain("start_at", "<=", fiscal_lock_date), |
| 59 |
Domain("start_at", "<=", record.user_tax_lock_date), |
| 60 |
|
| 61 |
Domain("config_id.journal_id.type", "=", 'sale') |
| 62 |
& Domain("start_at", "<=", record.user_sale_lock_date), |
| 63 |
)) |
| 64 |
) |
| 65 |
if sessions_in_period: |
| 66 |
sessions_str = ', '.join(sessions_in_period.mapped('name')) |
| 67 |
raise ValidationError(_("Please close all the point of sale sessions in this period before closing it. Open sessions are: %s ", sessions_str)) |