from odoo import models


class AccountExternalTaxMixin(models.AbstractModel):
    _inherit = 'account.external.tax.mixin'

    def _get_avatax_line_addresses(self, partner, warehouse_id):

        res = {
            'shipFrom': self._get_avatax_address_from_partner(warehouse_id.partner_id),
            'shipTo': self._get_avatax_address_from_partner(partner),
        }
        return res

    def _get_avatax_invoice_line(self, line_data):
        res = super()._get_avatax_invoice_line(line_data)

        warehouse = line_data['warehouse_id']
        if warehouse and warehouse.partner_id != self.company_id.partner_id:
            res['addresses'] = self._get_avatax_line_addresses(self._get_avatax_ship_to_partner(), warehouse)

        return res
