Odoo18-Base/addons/l10n_in_sale/models/sale_order.py
2025-03-10 11:12:23 +07:00

59 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
l10n_in_reseller_partner_id = fields.Many2one('res.partner',
string='Reseller', domain="[('vat', '!=', False), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]})
l10n_in_journal_id = fields.Many2one('account.journal', string="Journal", compute="_compute_l10n_in_journal_id", store=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]})
l10n_in_gst_treatment = fields.Selection([
('regular', 'Registered Business - Regular'),
('composition', 'Registered Business - Composition'),
('unregistered', 'Unregistered Business'),
('consumer', 'Consumer'),
('overseas', 'Overseas'),
('special_economic_zone', 'Special Economic Zone'),
('deemed_export', 'Deemed Export'),
('uin_holders', 'UIN Holders'),
], string="GST Treatment", readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, compute="_compute_l10n_in_gst_treatment", store=True)
@api.depends('partner_id')
def _compute_l10n_in_gst_treatment(self):
for order in self:
# set default value as False so CacheMiss error never occurs for this field.
order.l10n_in_gst_treatment = False
if order.country_code == 'IN':
l10n_in_gst_treatment = order.partner_id.l10n_in_gst_treatment
if not l10n_in_gst_treatment and order.partner_id.country_id and order.partner_id.country_id.code != 'IN':
l10n_in_gst_treatment = 'overseas'
if not l10n_in_gst_treatment:
l10n_in_gst_treatment = order.partner_id.vat and 'regular' or 'consumer'
order.l10n_in_gst_treatment = l10n_in_gst_treatment
@api.depends('company_id')
def _compute_l10n_in_journal_id(self):
for order in self:
if order._origin and order._origin.company_id == order.company_id and order.l10n_in_journal_id.company_id == order.company_id:
continue
# set default value as False so CacheMiss error never occurs for this field.
order.l10n_in_journal_id = False
if order.country_code == 'IN':
domain = [('company_id', '=', order.company_id.id), ('type', '=', 'sale')]
journal = self.env['account.journal'].search(domain, limit=1)
if journal:
order.l10n_in_journal_id = journal.id
def _prepare_invoice(self):
invoice_vals = super(SaleOrder, self)._prepare_invoice()
if self.country_code == 'IN':
invoice_vals['l10n_in_reseller_partner_id'] = self.l10n_in_reseller_partner_id.id
if self.l10n_in_journal_id:
invoice_vals['journal_id'] = self.l10n_in_journal_id.id
invoice_vals['l10n_in_gst_treatment'] = self.l10n_in_gst_treatment
return invoice_vals