diff --git a/.copier-answers.yml b/.copier-answers.yml index 9b599b89..67ad86e4 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Do NOT update manually; changes here will be overwritten by Copier -_commit: d46567f +_commit: 2f2f7c4 _src_path: https://github.com/ingadhoc/addons-repo-template.git description: ADHOC Odoo purchase Modules is_private: false diff --git a/purchase_order_type_ux/__manifest__.py b/purchase_order_type_ux/__manifest__.py index 28ed2797..2d823314 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.1.0", + "version": "18.0.1.2.0", "category": "Purchases", "sequence": 14, "summary": "", @@ -28,10 +28,9 @@ "website": "www.adhoc.com.ar", "license": "AGPL-3", "images": [], - "depends": ["project", "purchase_stock_ux", "l10n_ar_purchase", "purchase_order_type", "account_multicompany_ux"], + "depends": ["purchase_stock_ux", "l10n_ar_purchase", "purchase_order_type", "account_multicompany_ux"], "data": [ "views/purchase_order_type_views.xml", - "views/account_move_views.xml", "report/purchase_quotation_templates.xml", ], "installable": True, diff --git a/purchase_order_type_ux/models/__init__.py b/purchase_order_type_ux/models/__init__.py index ce5178b8..70cbde64 100644 --- a/purchase_order_type_ux/models/__init__.py +++ b/purchase_order_type_ux/models/__init__.py @@ -1,4 +1,3 @@ from . import purchase_order_type from . import purchase_order from . import purchase_order_line -from . import account_move diff --git a/purchase_order_type_ux/models/account_move.py b/purchase_order_type_ux/models/account_move.py deleted file mode 100644 index e0d1aa40..00000000 --- a/purchase_order_type_ux/models/account_move.py +++ /dev/null @@ -1,81 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -# Copyright 2020 Tecnativa - Pedro M. Baeza - -from odoo import api, fields, models - - -class AccountMove(models.Model): - _inherit = "account.move" - - purchase_type_id = fields.Many2one( - comodel_name="purchase.order.type", - string="Purchase Type", - compute="_compute_purchase_type_id", - store=True, - readonly=False, - ondelete="restrict", - copy=True, - precompute=True, - ) - - @api.depends("partner_id", "company_id", "move_type") - def _compute_purchase_type_id(self): - purchase_type = self.env["purchase.order.type"].browse() - for record in self: - if record.move_type not in ["in_invoice", "in_refund"]: - record.purchase_type_id = purchase_type - continue - else: - record.purchase_type_id = record._origin.purchase_type_id - if not record.partner_id: - record.purchase_type_id = self.env["purchase.order.type"].search( - [("company_id", "in", [self.env.company.id, False])], limit=1 - ) - else: - purchase_type = ( - record.partner_id.with_company(record.company_id).purchase_type - or record.partner_id.commercial_partner_id.with_company(record.company_id).purchase_type - ) - if purchase_type: - record.purchase_type_id = purchase_type - if ( - record.purchase_type_id - and record.purchase_type_id.journal_id.company_id.id not in record.env.companies.ids - and not record.partner_id - ): - record.purchase_type_id = self.env["purchase.order.type"].search( - [ - ("company_id", "in", [record.company_id.id, False]), - "|", - ("journal_id", "=", False), - ("journal_id.company_id", "=", record.company_id.id), - ], - limit=1, - ) - - @api.depends("purchase_type_id") - def _compute_invoice_payment_term_id(self): - res = super()._compute_invoice_payment_term_id() - for move in self.filtered("purchase_type_id.payment_term_id"): - move.invoice_payment_term_id = move.purchase_type_id.payment_term_id - return res - - @api.depends("purchase_type_id") - def _compute_journal_id(self): - res = super()._compute_journal_id() - for move in self.filtered("purchase_type_id.journal_id"): - 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") - def _onchange_journal(self): - if self.journal_id and self.journal_id.currency_id: - new_currency = self.journal_id.currency_id - if new_currency != self.currency_id: - self.currency_id = new_currency - self._compute_currency_rate() - if self.state == "draft" and self._get_last_sequence() and self.name and self.name != "/": - self.name = "/" diff --git a/purchase_order_type_ux/models/purchase_order.py b/purchase_order_type_ux/models/purchase_order.py index e74fba63..797c15bf 100644 --- a/purchase_order_type_ux/models/purchase_order.py +++ b/purchase_order_type_ux/models/purchase_order.py @@ -18,8 +18,6 @@ def create(self, vals): def onchange_order_type(self): super().onchange_order_type() for order in self: - if order.order_type.project_id: - 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: @@ -43,8 +41,6 @@ def _prepare_invoice(self): 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 def action_create_invoice(self): @@ -53,17 +49,20 @@ def action_create_invoice(self): for the company of the invoice. In cases where the company has a localization (e.g., l10n_ar), this ensures that the taxes from `l10n_ar_tax_ids` are applied. """ + if len(self.mapped("order_type")) > 1: + raise ValueError("This method only works for purchase orders of the same type") action = super().action_create_invoice() - invoices = self.invoice_ids.filtered(lambda m: m.state == "draft") - for invoice in invoices.filtered("purchase_type_id.journal_id"): - company = invoice.purchase_type_id.journal_id.company_id - if invoice.company_id != company: + order_type = self[:1].order_type + if order_type.journal_id and order_type.journal_id.company_id != self.company_id: + invoices = self.mapped("invoice_ids").filtered(lambda m: m.state == "draft") + company = order_type.journal_id.company_id + for invoice in invoices: 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, + "journal_id": order_type.journal_id.id, } ) acc.change_company() diff --git a/purchase_order_type_ux/models/purchase_order_type.py b/purchase_order_type_ux/models/purchase_order_type.py index aaec75dc..5b2218cd 100644 --- a/purchase_order_type_ux/models/purchase_order_type.py +++ b/purchase_order_type_ux/models/purchase_order_type.py @@ -1,7 +1,7 @@ # Copyright (C) 2015 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import fields, models class PurchaseOrderType(models.Model): @@ -11,14 +11,11 @@ class PurchaseOrderType(models.Model): "res.partner", help="For the Sale Report, The information of the partner will be used to fill the report header.", ) + # los comentamos en vista, los dejamos por ahora en python, los deprecamos en 19 partner_id = fields.Many2many( "res.partner", "Supplier", ) - project_id = fields.Many2one( - "project.project", - help="Select to define the analytics account", - ) journal_id = fields.Many2one( "account.journal", domain="[('type', '=', 'purchase')]", @@ -46,9 +43,3 @@ class PurchaseOrderType(models.Model): 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): - for rec in self: - if rec.partner_id: - rec.partner_id.purchase_type = rec.id diff --git a/purchase_order_type_ux/views/account_move_views.xml b/purchase_order_type_ux/views/account_move_views.xml deleted file mode 100644 index 9a610f06..00000000 --- a/purchase_order_type_ux/views/account_move_views.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - account.move.form.pot - account.move - - - - - - - - - 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 11eb075a..1584b5a5 100644 --- a/purchase_order_type_ux/views/purchase_order_type_views.xml +++ b/purchase_order_type_ux/views/purchase_order_type_views.xml @@ -17,11 +17,10 @@ - + - @@ -34,20 +33,13 @@ - - + -