This question has been flagged

Hello,

I have the following problem:

class AccountInvoice (models.Model):

     _inherit = 'account.invoice'

         payment_method = fields.Selection (

                 [

                     ('01', 'Without Use of the Financial System'),

                     ('06', 'Account Debit'),

                     ('19', 'Credit Card'),

                     ('20', 'Others with Use of the Financial System'),

                 ],

                 string = 'Payment Method',

                 required = True,

                 default = '01 ',

                 help = 'Forms of Payment'

         )


         @ api.onchange ('payment_method')

             def do_stuff (self):

                   ???


The conversion will be like:

('01', 'Without Use of the Financial System')        --> Keeps the partner fiscal_position_id

('06', 'Account Debit')                                               --> Changes the fiscal_position_id to "Purchase                                                                                              Payment Debit Agreement"

 ('19', 'Credit Card')                                                   --> Changes the fiscal_position_id to "Purchase 

                                                                                          Purchase Credit Card Payment"

('20', 'Others with Use of the Financial System') --> Keeps the partner fiscal_position_id


What I need is to change the "fiscal_position_id" field when I change the payment_method selection. I don't know how to deal with this problem. The tax positions that I have created have tax mapping tables, so it is very important to facilitate the purchasing operator to indicate the payment method and its corresponding tax position.

I thank you all in advance for your help and assistance.

Avatar
Discard
Author Best Answer

I found by my self the way to change the fiscal_position_id selection changing a payment_method selection on an in_invoice:


 @api.onchange('payment_method')

    def change_fiscal_position(self):

        self.ensure_one()

        FISCAL = self.env['account.fiscal.position']

        fiscal_position = {}

        if self.payment_method == "10" or self.payment_method == "19":      # 10 o 19 Tarjeta de Crédito 

            fiscal_position = FISCAL.browse([11])                           # 11 Compras Pago Tarjeta Crédito

        elif self.payment_method == "16":                                   # 16 Tarjeta de Débito 

            fiscal_position = FISCAL.browse([11])                           # 11 Compras Pago Tarjeta Crédito

        elif self.payment_method == "06":                                   # 06 Débito de Cuenta

            fiscal_position = FISCAL.browse([10])                           # 10 Compras Pago Convenio Débito           

        else:                                                                                       # Others

            fiscal_position = self.partner_id.property_account_position_id          # Keeps Partner Fiscal Position 

        if fiscal_position:

            self.fiscal_position_id = fiscal_position

        return {}

Avatar
Discard