(self, soft=True)
return posted
Use journal type to define document type because not miss state in any entry including POS entry
Use journal type to define document type because not miss state in any entry including POS entry
Use journal type to define document type because not miss state in any entry including POS entry
def _post(self, soft=True):
        """Use journal type to define document type because not miss state in any entry including POS entry"""
        posted = super()._post(soft)
        gst_treatment_name_mapping = {k: v for k, v in
                             self._fields['l10n_in_gst_treatment']._description_selection(self.env)}
        for move in posted.filtered(lambda m: m.country_code == 'IN'):
            """Check state is set in company/sub-unit"""
            company_unit_partner = move.journal_id.l10n_in_gstin_partner_id or move.journal_id.company_id
            if not company_unit_partner.state_id:
                raise ValidationError(_(
                    "State is missing from your company/unit %(company_name)s (%(company_id)s).\nFirst set state in your company/unit.",
                    company_name=company_unit_partner.name,
                    company_id=company_unit_partner.id
                ))
            elif move.journal_id.type == 'purchase':
                move.l10n_in_state_id = company_unit_partner.state_id

            shipping_partner = move._l10n_in_get_shipping_partner()
            # In case of shipping address does not have GSTN then also check customer(partner_id) GSTN
            # This happens when Bill-to Ship-to transaction where shipping(Ship-to) address is unregistered and customer(Bill-to) is registred.
            move.l10n_in_gstin = move._l10n_in_get_shipping_partner_gstin(shipping_partner) or move.partner_id.vat
            if not move.l10n_in_gstin and move.l10n_in_gst_treatment in ['regular', 'composition', 'special_economic_zone', 'deemed_export']:
                raise ValidationError(_(
                    "Partner %(partner_name)s (%(partner_id)s) GSTIN is required under GST Treatment %(name)s",
                    partner_name=shipping_partner.name,
                    partner_id=shipping_partner.id,
                    name=gst_treatment_name_mapping.get(move.l10n_in_gst_treatment)
                ))
            if move.journal_id.type == 'sale':
                move.l10n_in_state_id = self._l10n_in_get_indian_state(shipping_partner)
                if not move.l10n_in_state_id:
                    move.l10n_in_state_id = self._l10n_in_get_indian_state(move.partner_id)
                #still state is not set then assumed that transaction is local like PoS so set state of company unit
                if not move.l10n_in_state_id:
                    move.l10n_in_state_id = company_unit_partner.state_id
        return posted
def _post ( self , soft = True ) : posted = super ( ) . _post ( soft ) gst_treatment_name_mapping = { k : v for k , v in self . _fields [ 'l10n_in_gst_treatment' ] . _description_selection ( self . env ) } for move in posted . filtered ( lambda m : m . country_code == 'IN' ) : """Check state is set in company/sub-unit""" company_unit_partner = move . journal_id . l10n_in_gstin_partner_id or move . journal_id . company_id if not company_unit_partner . state_id : raise ValidationError ( _ ( "State is missing from your company/unit %(company_name)s (%(company_id)s).\nFirst set state in your company/unit." , company_name = company_unit_partner . name , company_id = company_unit_partner . id ) ) elif move . journal_id . type == 'purchase' : move . l10n_in_state_id = company_unit_partner . state_id shipping_partner = move . _l10n_in_get_shipping_partner ( ) # In case of shipping address does not have GSTN then also check customer(partner_id) GSTN # This happens when Bill-to Ship-to transaction where shipping(Ship-to) address is unregistered and customer(Bill-to) is registred. move . l10n_in_gstin = move . _l10n_in_get_shipping_partner_gstin ( shipping_partner ) or move . partner_id . vat if not move . l10n_in_gstin and move . l10n_in_gst_treatment in [ 'regular' , 'composition' , 'special_economic_zone' , 'deemed_export' ] : raise ValidationError ( _ ( "Partner %(partner_name)s (%(partner_id)s) GSTIN is required under GST Treatment %(name)s" , partner_name = shipping_partner . name , partner_id = shipping_partner . id , name = gst_treatment_name_mapping . get ( move . l10n_in_gst_treatment ) ) ) if move . journal_id . type == 'sale' : move . l10n_in_state_id = self . _l10n_in_get_indian_state ( shipping_partner ) if not move . l10n_in_state_id : move . l10n_in_state_id = self . _l10n_in_get_indian_state ( move . partner_id ) #still state is not set then assumed that transaction is local like PoS so set state of company unit if not move . l10n_in_state_id : move . l10n_in_state_id = company_unit_partner . state_id return posted