diff --git a/purchase_order_type_ux/__manifest__.py b/purchase_order_type_ux/__manifest__.py index cfc388db..28ed2797 100644 --- a/purchase_order_type_ux/__manifest__.py +++ b/purchase_order_type_ux/__manifest__.py @@ -20,7 +20,7 @@ { "name": "Purchase Order Type UX", - "version": "18.0.1.0.0", + "version": "18.0.1.1.0", "category": "Purchases", "sequence": 14, "summary": "", @@ -28,12 +28,7 @@ "website": "www.adhoc.com.ar", "license": "AGPL-3", "images": [], - "depends": [ - "project", - "purchase_stock_ux", - "l10n_ar_purchase", - "purchase_order_type", - ], + "depends": ["project", "purchase_stock_ux", "l10n_ar_purchase", "purchase_order_type", "account_multicompany_ux"], "data": [ "views/purchase_order_type_views.xml", "views/account_move_views.xml", diff --git a/purchase_order_type_ux/i18n/es.po b/purchase_order_type_ux/i18n/es.po index ec43ee00..19e9d967 100644 --- a/purchase_order_type_ux/i18n/es.po +++ b/purchase_order_type_ux/i18n/es.po @@ -4,14 +4,15 @@ # # Translators: # Juan José Scarafía , 2025 +# migration.bot.adhoc, 2025 # msgid "" msgstr "" "Project-Id-Version: Odoo Server 18.0+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-08-11 15:47+0000\n" +"POT-Creation-Date: 2025-11-25 12:46+0000\n" "PO-Revision-Date: 2025-08-11 15:47+0000\n" -"Last-Translator: Juan José Scarafía , 2025\n" +"Last-Translator: migration.bot.adhoc, 2025\n" "Language-Team: Spanish (https://app.transifex.com/adhoc/teams/46451/es/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -108,6 +109,11 @@ msgstr "" msgid "Select to define the analytics account" msgstr "" +#. module: purchase_order_type_ux +#: model:ir.model.fields,field_description:purchase_order_type_ux.field_purchase_order_line__taxes_id +msgid "Taxes" +msgstr "Impuestos" + #. module: purchase_order_type_ux #: model:ir.model.fields,help:purchase_order_type_ux.field_purchase_order_type__picking_type_id msgid "This will determine operation type of incoming shipment" diff --git a/purchase_order_type_ux/models/account_move.py b/purchase_order_type_ux/models/account_move.py index e7f05b1d..e0d1aa40 100644 --- a/purchase_order_type_ux/models/account_move.py +++ b/purchase_order_type_ux/models/account_move.py @@ -64,9 +64,10 @@ def _compute_invoice_payment_term_id(self): def _compute_journal_id(self): res = super()._compute_journal_id() for move in self.filtered("purchase_type_id.journal_id"): - move.journal_id = move.purchase_type_id.journal_id - if move.purchase_type_id.journal_id: - move._onchange_journal() + if move.purchase_type_id.journal_id.company_id.id == move.company_id.id: + move.journal_id = move.purchase_type_id.journal_id + if move.purchase_type_id.journal_id: + move._onchange_journal() return res @api.onchange("journal_id") diff --git a/purchase_order_type_ux/models/purchase_order.py b/purchase_order_type_ux/models/purchase_order.py index 63a91f5b..e74fba63 100644 --- a/purchase_order_type_ux/models/purchase_order.py +++ b/purchase_order_type_ux/models/purchase_order.py @@ -7,6 +7,13 @@ class PurchaseOrder(models.Model): _inherit = "purchase.order" + @api.model_create_multi + def create(self, vals): + res = super().create(vals) + if res.order_type and res.order_type.fiscal_position_id: + res.fiscal_position_id = res.order_type.fiscal_position_id + return res + @api.onchange("order_type") def onchange_order_type(self): super().onchange_order_type() @@ -15,15 +22,16 @@ def onchange_order_type(self): order.project_id = order.order_type.project_id if order.order_type.picking_type_id: order.picking_type_id = order.order_type.picking_type_id + if order.order_type.fiscal_position_id: + order.fiscal_position_id = order.order_type.fiscal_position_id def _prepare_invoice(self): if not self.order_type.journal_id: return super()._prepare_invoice() res = super()._prepare_invoice() company = self.order_type.journal_id.company_id - self = self.with_company(company.id) + journal = self.env["account.journal"].browse(res.get("journal_id")) if res.get("journal_id") else False if company != self.company_id: - res["company_id"] = company.id # En purchase, partner_bank_id es del proveedor, no de la compañía partner_bank_id = self.partner_id.commercial_partner_id.bank_ids.filtered_domain( ["|", ("company_id", "=", False), ("company_id", "=", company.id)] @@ -32,15 +40,9 @@ def _prepare_invoice(self): # agregamos para que recompute term y cond si la nueva compañia los tiene por defecto if "narration" in res and not res["narration"]: del res["narration"] - po_fiscal_position = self.env["account.fiscal.position"].browse(res["fiscal_position_id"]) - if not po_fiscal_position or (po_fiscal_position.company_id and po_fiscal_position.company_id != company): - partner_invoice = self.env["res.partner"].browse(self.partner_id.address_get(["invoice"])["invoice"]) - res["fiscal_position_id"] = ( - self.env["account.fiscal.position"] - .with_company(company.id) - ._get_fiscal_position(partner_invoice) - .id - ) + if journal and journal.company_id.id != self.company_id.id: + res.pop("journal_id") + if self.order_type: res["purchase_type_id"] = self.order_type.id return res @@ -53,8 +55,17 @@ def action_create_invoice(self): """ action = super().action_create_invoice() invoices = self.invoice_ids.filtered(lambda m: m.state == "draft") - for line in invoices.invoice_line_ids: - purchase_line = line.purchase_line_id - if purchase_line and line.move_id.company_id != purchase_line.order_id.company_id: - line.tax_ids = line._get_computed_taxes() + for invoice in invoices.filtered("purchase_type_id.journal_id"): + company = invoice.purchase_type_id.journal_id.company_id + if invoice.company_id != company: + acc = self.env["account.change.company"].create( + { + "move_id": invoice.id, + "company_ids": [invoice.company_id.id, company.id], + "company_id": company.id, + "journal_id": invoice.purchase_type_id.journal_id.id, + } + ) + acc.change_company() + invoice.partner_bank_id = company.partner_id.bank_ids[:1].id return action diff --git a/purchase_order_type_ux/models/purchase_order_line.py b/purchase_order_type_ux/models/purchase_order_line.py index 9dc84685..b190ff20 100644 --- a/purchase_order_type_ux/models/purchase_order_line.py +++ b/purchase_order_type_ux/models/purchase_order_line.py @@ -24,19 +24,17 @@ def _prepare_account_move_line(self, move=False): """ Forzamos compania de diario de purchase type """ - if not self.order_id.order_type.journal_id: - return super()._prepare_account_move_line(move=move) - company = self.order_id.order_type.journal_id.company_id - self = self.with_company(company.id) res = super()._prepare_account_move_line(move=move) - - if company != self.company_id: - # Because we not have the access to the invoice, we obtain the fiscal position who - # has the invoice really - partner_invoice = self.env["res.partner"].browse(self.partner_id.address_get(["invoice"])["invoice"]) - fpos = self.env["account.fiscal.position"].with_company(company.id)._get_fiscal_position(partner_invoice) - taxes = self.product_id.supplier_taxes_id.filtered(lambda r: company == r.company_id) - taxes = fpos.map_tax(taxes) if fpos else taxes - - res["tax_ids"] = [(6, 0, taxes.ids)] + downpayment_lines = self.invoice_lines.filtered("is_downpayment") + account_id = self.env["account.account"].browse(res["account_id"]) if res.get("account_id") else None + if ( + self.is_downpayment + and downpayment_lines + and account_id + and self.company_id.id not in account_id.company_ids.ids + ): + account_id = self.env["account.change.company"]._get_change_downpayment_account( + self.company_id, self.invoice_lines, self.order_id.fiscal_position_id + ) + res["account_id"] = account_id.id return res diff --git a/purchase_order_type_ux/models/purchase_order_type.py b/purchase_order_type_ux/models/purchase_order_type.py index 117d5bfb..aaec75dc 100644 --- a/purchase_order_type_ux/models/purchase_order_type.py +++ b/purchase_order_type_ux/models/purchase_order_type.py @@ -39,6 +39,13 @@ class PurchaseOrderType(models.Model): domain="['|', ('warehouse_id', '=', False), ('warehouse_id.company_id', '=', company_id)]", help="This will determine operation type of incoming shipment", ) + fiscal_position_id = fields.Many2one( + "account.fiscal.position", + string="Fiscal Position", + check_company=True, + help="If you choose a fiscal position then this fiscal positioon would be used as default instead of the " + "automatically detected or setted on the partner", + ) @api.constrains("partner_id") def _compute_partner_purchase_order_type(self): diff --git a/purchase_order_type_ux/views/purchase_order_type_views.xml b/purchase_order_type_ux/views/purchase_order_type_views.xml index 36bbcd51..11eb075a 100644 --- a/purchase_order_type_ux/views/purchase_order_type_views.xml +++ b/purchase_order_type_ux/views/purchase_order_type_views.xml @@ -6,6 +6,7 @@ + @@ -23,6 +24,7 @@ + @@ -37,6 +39,7 @@ + , 2024 # María Florencia Frigieri Parma, 2025 # Matias Velazquez, 2025 -# ADHOC - Bot , 2025 +# migration.bot.adhoc, 2025 # msgid "" msgstr "" "Project-Id-Version: Odoo Server 18.0+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-03 02:38+0000\n" +"POT-Creation-Date: 2025-11-28 02:43+0000\n" "PO-Revision-Date: 2024-11-20 17:23+0000\n" -"Last-Translator: ADHOC - Bot , 2025\n" +"Last-Translator: migration.bot.adhoc, 2025\n" "Language-Team: Spanish (https://app.transifex.com/adhoc/teams/46451/es/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n"