Я хочу сохранить данные из шаблона в два модальных сквозных контроллера, которыми я поделился кодом - PullRequest
0 голосов
/ 28 мая 2019

Я уже делаю представления и шаблон этих модальных ... При отправке формы данные полей 'Зарплата' будут размещаться в двух модальных файлах tax.income (данные из 3 полей в этом модале) и tax.wage ( данные 3 полей в этом модале.

Контроллер:

    from odoo.http import request, route, Controller

    class TaxIncome(Controller):

        @route(['/tax_income'], type='http', auth='user', website='True')
        def tax_income(self, redirect=None, **post):
            income_obj = self.get_income_record()
            if post.get("key") == "salary":
                self.add_salary(income_obj, post)

                # Bank Interest
            if post.get("key") == "interest":
                self.add_interest(income_obj, post)

                # Dividends
            if post.get("key") == "dividend":
                self.add_dividends(income_obj, post)
            # return request.redirect('/my/account?page=1')

        def get_income_record(self):
            """

            :param data:
            :return:
            """
            partner_id = request.env.user.partner_id.id
            income_record = request.env['tax.income'].sudo().search([("partner_id", "=", partner_id)])

            if not income_record:
                income_record = request.env['tax.income'].sudo().create({"partner_id": partner_id})
                request.env.cr.commit()
            return income_record

        def add_salary(self, obj, data):
            """

            :param obj:
            :param data:
            :return:
            """
          obj.wage_past_year = data.get("wage_past_year")
          obj.other_income_note = data.get("other_income_note")
          obj.copy_payg_statement = data.get("copy_payg_statement")
          obj.payers_abn = data.get("payers_abn")
          obj.total_tax_Withheld = data.get("total_tax_Withheld")
          obj.gross_payments_income = data.get("gross_payments_income")
          request.env.cr.commit()

        def add_dividends(self, obj, data):
            """

            :param obj:
            :param data:
            :return:
            """
            obj.tfn_amounts_withheld_dividends = data.get("tfn_amounts_withheld_dividends", None)
            obj.unfranked_amount = data.get("unfranked_amount", None)
            obj.franked_amount = data.get("franked_amount", None)
            obj.franking_credit = data.get("franking_credit", None)
            request.env.cr.commit()

        def add_interest(self, obj, data):
            """

            :param obj:
            :param data:
            :return:
            """
            obj.tax_withheld_interest = data.get("tax_withheld_interest", 0.0)
            obj.total_interest_received = data.get("total_interest_received", 0.0)
            request.env.cr.commit()

    class Income(models.Model):
        _name = 'tax.income'
        currency_id = fields.Many2one(
            'res.currency')
        income_id = fields.Char('Income')
        partner_id = fields.Many2one('res.partner', 'Partner')
        year_id = fields.Char('Year')
        type_id = fields.Char('Type')
        amount_id = fields.Char('Amount')
    #Salary 
        wage_past_year = fields.Boolean('Past Year Salary/income')
        other_income_note = fields.Text('Other Income Note')
        copy_payg_statement = fields.Binary("Attached  copy of PAYG statement")
        wage_ids = fields.One2many('tax.wage', 'wage_id')
        # Interest
        tax_withheld_interest = fields.Monetary("Total tax withheld from interest ")
        total_interest_received = fields.Monetary("Total interest received")
        # Dividends
        tfn_amounts_withheld_dividends = fields.Monetary("TFN amounts withheld dividends")
        unfranked_amount = fields.Monetary("Unfranked amount")
        franked_amount = fields.Monetary("Franked amount")
        franking_credit = fields.Monetary("Franking credit")

    class SalaryWage(models.Model):
        """

        """
        _name = 'tax.wage'

        currency_id = fields.Many2one(
            'res.currency')
        wage_id = fields.Many2one('tax.income')
        payers_abn = fields.Integer('Payer ABN')
        tax_withheld = fields.Monetary("Total Tax Withheld")
        gross_payments_income = fields.Monetary("Gross Payments")
        income_id = fields.Many2one('tax.income')

Modal
        class Income(models.Model):
            _name = 'tax.income'
            currency_id = fields.Many2one(
                'res.currency')
            income_id = fields.Char('Income')
            partner_id = fields.Many2one('res.partner', 'Partner')
            year_id = fields.Char('Year')
            type_id = fields.Char('Type')
            amount_id = fields.Char('Amount')
            # Salary
            wage_past_year = fields.Boolean('Past Year Salary/income')
            other_income_note = fields.Text('Other Income Note')
            copy_payg_statement = fields.Binary("Attached  copy of PAYG statement")
            wage_ids = fields.One2many('tax.wage', 'wage_id')
            # Interest
            tax_withheld_interest = fields.Monetary("Total tax withheld from interest ")
            total_interest_received = fields.Monetary("Total interest received")
            # Dividends
            tfn_amounts_withheld_dividends = fields.Monetary("TFN amounts withheld dividends")
            unfranked_amount = fields.Monetary("Unfranked amount")
            franked_amount = fields.Monetary("Franked amount")
            franking_credit = fields.Monetary("Franking credit")

            # Rent
            # rent_id = fields.One2many('tax.rent', 'rent_sheet_id')
            # gross_rent = fields.Monetary('Gross rent')
            # interest_deductions = fields.Monetary('Interest deductions')
            # capital_works_deductions = fields.Monetary('Capital works deductions')
            # other_rental_deductions = fields.Monetary('Other rental deductions')

 #Salary Modal   
    class SalaryWage(models.Model):
        """

        """
        _name = 'tax.wage'

        currency_id = fields.Many2one(
            'res.currency')
        wage_id = fields.Many2one('tax.income')
        payers_abn = fields.Integer('Payer ABN')
        tax_withheld = fields.Monetary("Total Tax Withheld")
        gross_payments_income = fields.Monetary("Gross Payments")
        income_id = fields.Many2one('tax.income')

Я уже делаю представления и шаблон этих модальных ... При отправке формы данные полей 'Зарплата' будут размещаться в двух модальных моделях tax.income (данные из 3 полей в этом модальном) и tax.wage ( данные 3 полей в этом модале.

...