diff --git a/account_invoice_subcontractor/__manifest__.py b/account_invoice_subcontractor/__manifest__.py index 3dae256..84751b1 100644 --- a/account_invoice_subcontractor/__manifest__.py +++ b/account_invoice_subcontractor/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Invoice Subcontractor", - "version": "14.0.0.0.2", + "version": "16.0.1.0.0", "category": "Generic Modules/Others", "license": "AGPL-3", "author": "Akretion", @@ -12,16 +12,16 @@ "depends": [ "hr", "account_invoice_inter_company", - "onchange_helper", "sale", ], "data": [ "data/cron_data.xml", "security/security.xml", "security/ir.model.access.csv", - "views/hr_view.xml", + "views/hr_employee_view.xml", "views/subcontractor_work_view.xml", - "views/invoice_view.xml", + "views/account_move_view.xml", + "views/account_move_line_view.xml", "wizard/subcontractor_invoice_work_view.xml", "views/product_view.xml", "wizard/res_config_settings.xml", diff --git a/account_invoice_subcontractor/migrations/14.0.0.0.1/post-migration.py b/account_invoice_subcontractor/migrations/14.0.0.0.1/post-migration.py deleted file mode 100644 index bf6707b..0000000 --- a/account_invoice_subcontractor/migrations/14.0.0.0.1/post-migration.py +++ /dev/null @@ -1,89 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - invoice_line_id = aml.id - FROM account_invoice_line ail - JOIN account_move_line aml ON aml.old_invoice_line_id = ail.id - WHERE subcontractor_work.old_invoice_line_id = ail.id - AND subcontractor_work.old_invoice_line_id IS NOT NULL - """, - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - invoice_id = am.id, - invoice_date = am.invoice_date - FROM account_invoice ai - JOIN account_move am ON am.old_invoice_id = ai.id - WHERE subcontractor_work.old_invoice_id = ai.id - AND subcontractor_work.old_invoice_id IS NOT NULL - """, - ) - - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - supplier_invoice_line_id = aml.id - FROM account_invoice_line ail - JOIN account_move_line aml ON aml.old_invoice_line_id = ail.id - WHERE subcontractor_work.old_supplier_invoice_line_id = ail.id - AND subcontractor_work.old_supplier_invoice_line_id IS NOT NULL - """, - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - supplier_invoice_id = am.id - FROM account_invoice ai - JOIN account_move am ON am.old_invoice_id = ai.id - WHERE subcontractor_work.old_supplier_invoice_id = ai.id - AND subcontractor_work.old_supplier_invoice_id IS NOT NULL - """, - ) - - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - subcontractor_invoice_line_id = aml.id - FROM account_invoice_line ail - JOIN account_move_line aml ON aml.old_invoice_line_id = ail.id - WHERE subcontractor_work.old_subcontractor_invoice_line_id = ail.id - AND subcontractor_work.old_subcontractor_invoice_line_id IS NOT NULL - """, - ) - - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - state = 'posted' - WHERE state = 'open' - """, - ) - - openupgrade.logged_query( - env.cr, - """ - UPDATE subcontractor_work - SET - subcontractor_state = 'posted' - WHERE subcontractor_state = 'open' - """, - ) diff --git a/account_invoice_subcontractor/migrations/14.0.0.0.1/pre-migration.py b/account_invoice_subcontractor/migrations/14.0.0.0.1/pre-migration.py deleted file mode 100644 index 7562805..0000000 --- a/account_invoice_subcontractor/migrations/14.0.0.0.1/pre-migration.py +++ /dev/null @@ -1,44 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - # Rename column so we keep the data but leave the update of the module create - # a new column with a foreign key towards account.move - # in post migration we'll manage the migraiton of the data from old field to new one - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE subcontractor_work - RENAME COLUMN invoice_line_id TO old_invoice_line_id; - """, - ) - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE subcontractor_work - RENAME COLUMN invoice_id TO old_invoice_id; - """, - ) - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE subcontractor_work - RENAME COLUMN supplier_invoice_line_id TO old_supplier_invoice_line_id; - """, - ) - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE subcontractor_work - RENAME COLUMN supplier_invoice_id TO old_supplier_invoice_id; - """, - ) - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE subcontractor_work - RENAME COLUMN subcontractor_invoice_line_id TO old_subcontractor_invoice_line_id; - """, - ) diff --git a/account_invoice_subcontractor/models/__init__.py b/account_invoice_subcontractor/models/__init__.py index d1309a4..f7f1602 100644 --- a/account_invoice_subcontractor/models/__init__.py +++ b/account_invoice_subcontractor/models/__init__.py @@ -1,6 +1,6 @@ from . import subcontractor_work -from . import hr -from . import invoice -from . import product -from . import sale +from . import hr_employee +from . import account_move +from . import account_move_line +from . import product_template from . import res_company diff --git a/account_invoice_subcontractor/models/invoice.py b/account_invoice_subcontractor/models/account_move.py similarity index 50% rename from account_invoice_subcontractor/models/invoice.py rename to account_invoice_subcontractor/models/account_move.py index cc85732..213da29 100644 --- a/account_invoice_subcontractor/models/invoice.py +++ b/account_invoice_subcontractor/models/account_move.py @@ -7,138 +7,6 @@ from odoo.tools import float_compare -class AccountMoveLine(models.Model): - _inherit = "account.move.line" - - _map_type = { - "in_invoice": "supplier_invoice_line_id", - "out_invoice": "subcontractor_invoice_line_id", - "in_refund": "supplier_invoice_line_id", - "out_refund": "subcontractor_invoice_line_id", - } - - subcontracted = fields.Boolean() - subcontractor_work_ids = fields.One2many( - "subcontractor.work", "invoice_line_id", string="Subcontractor Work", copy=True - ) - subcontractor_work_invoiced_id = fields.Many2one( - "subcontractor.work", - compute="_compute_subcontractor_work_invoiced_id", - inverse="_inverse_subcontractor_work_invoiced_id", - string="Invoiced Work", - store=True, - ) - invalid_work_amount = fields.Boolean( - compute="_compute_invalid_work_amount", string="Work Amount Invalid", store=True - ) - subcontractors = fields.Char(string="Sub C.", compute="_compute_subcontractors") - - def _compute_subcontractors(self): - for rec in self: - rec.subcontractors = " / ".join( - list({x.employee_id.name[0:4] for x in rec.subcontractor_work_ids}) - ) - - @api.onchange("product_id") - def _onchange_product_id(self): - super()._onchange_product_id() - for rec in self: - rec.subcontracted = rec.product_id.subcontracted - - @api.depends("move_id", "move_id.move_type") - def _compute_subcontractor_work_invoiced_id(self): - for line in self: - field = self._map_type.get(line.move_id.move_type, False) - if field: - work_obj = self.env["subcontractor.work"] - work = work_obj.search([[field, "=", line.id]]) - if work: - line.subcontractor_work_invoiced_id = work.id - - def _inverse_subcontractor_work_invoiced_id(self): - for line in self: - work = line.subcontractor_work_invoiced_id - if work: - field = self._map_type.get(line.move_id.move_type, False) - if field: - work.sudo().write({field: line.id}) - - @api.depends( - "move_id", - "move_id.move_type", - "move_id.company_id", - "move_id.partner_id", - "subcontractor_work_invoiced_id", - "subcontractor_work_invoiced_id.cost_price", - "subcontractor_work_ids", - "subcontractor_work_ids.sale_price", - "price_subtotal", - "subcontracted", - ) - def _compute_invalid_work_amount(self): - for line in self: - if line.subcontracted: - if line.move_id.move_type in ["in_invoice", "in_refund"]: - line.invalid_work_amount = line._check_in_invoice_amount() - else: - line.invalid_work_amount = line._check_out_invoice_amount() - else: - if line.subcontractor_work_ids: - line.invalid_work_amount = line.price_subtotal - else: - line.invalid_work_amount = False - - def _check_in_invoice_amount(self): - return ( - abs(self.subcontractor_work_invoiced_id.cost_price - self.price_subtotal) - > 0.1 - ) - - def _check_out_invoice_amount(self): - # TODO FIXME - if self.move_id.company_id.id != 1: - # this mean Akretion - if self.move_id.partner_id.id == 1: - return ( - abs( - self.subcontractor_work_invoiced_id.cost_price - - self.price_subtotal - ) - > 0.1 - ) - else: - subtotal = sum(self.subcontractor_work_ids.mapped("sale_price")) - # we use a bigger diff to avoid issue with rounding - return abs(subtotal - self.price_subtotal) > 5 - - @api.model - def _prepare_account_move_line(self, dest_invoice, dest_company, form=False): - res = super()._prepare_account_move_line(dest_invoice, dest_company, form=form) - res["subcontractor_work_invoiced_id"] = self.subcontractor_work_invoiced_id.id - return res - - def edit_subcontractor(self): - view = { - "name": ("Details"), - "view_type": "form", - "view_mode": "form", - "res_model": "account.move.line", - "view_id": self.env.ref( - "account_invoice_subcontractor.view_move_line_subcontractor_form" - ).id, - "type": "ir.actions.act_window", - "target": "new", - "res_id": self.id, - } - return view - - @api.onchange("quantity") - def _onchange_quantity(self): - for line in self: - if len(line.subcontractor_work_ids) == 1: - line.subcontractor_work_ids.quantity = line.quantity - - class AccountMove(models.Model): _inherit = "account.move" diff --git a/account_invoice_subcontractor/models/account_move_line.py b/account_invoice_subcontractor/models/account_move_line.py new file mode 100644 index 0000000..efe5f7e --- /dev/null +++ b/account_invoice_subcontractor/models/account_move_line.py @@ -0,0 +1,138 @@ +# © 2015 Akretion +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + _map_type = { + "in_invoice": "supplier_invoice_line_id", + "out_invoice": "subcontractor_invoice_line_id", + "in_refund": "supplier_invoice_line_id", + "out_refund": "subcontractor_invoice_line_id", + } + + subcontracted = fields.Boolean(compute="_compute_subcontracted") + subcontractor_work_ids = fields.One2many( + "subcontractor.work", "invoice_line_id", string="Subcontractor Work", copy=True + ) + subcontractor_work_invoiced_id = fields.Many2one( + "subcontractor.work", + compute="_compute_subcontractor_work_invoiced_id", + inverse="_inverse_subcontractor_work_invoiced_id", + string="Invoiced Work", + store=True, + ) + invalid_work_amount = fields.Boolean( + compute="_compute_invalid_work_amount", string="Work Amount Invalid", store=True + ) + subcontractors = fields.Char(string="Sub C.", compute="_compute_subcontractors") + + def _compute_subcontractors(self): + for rec in self: + rec.subcontractors = " / ".join( + list({x.employee_id.name[0:4] for x in rec.subcontractor_work_ids}) + ) + + @api.depends("move_id", "move_id.move_type") + def _compute_subcontractor_work_invoiced_id(self): + for line in self: + field = self._map_type.get(line.move_id.move_type, False) + if field: + work_obj = self.env["subcontractor.work"] + work = work_obj.search([[field, "=", line.id]]) + if work: + line.subcontractor_work_invoiced_id = work.id + + def _inverse_subcontractor_work_invoiced_id(self): + for line in self: + work = line.subcontractor_work_invoiced_id + if work: + field = self._map_type.get(line.move_id.move_type, False) + if field: + work.sudo().write({field: line.id}) + + @api.depends("company_id") + def _compute_subcontracted(self): + for aml in self: + aml.subcontracted = aml.with_company( + aml.company_id + ).product_id.subcontracted + + @api.depends( + "move_id", + "move_id.move_type", + "move_id.company_id", + "move_id.partner_id", + "subcontractor_work_invoiced_id", + "subcontractor_work_invoiced_id.cost_price", + "subcontractor_work_ids", + "subcontractor_work_ids.sale_price", + "price_subtotal", + "subcontracted", + ) + def _compute_invalid_work_amount(self): + for line in self: + if line.subcontracted: + if line.move_id.move_type in ["in_invoice", "in_refund"]: + line.invalid_work_amount = line._check_in_invoice_amount() + else: + line.invalid_work_amount = line._check_out_invoice_amount() + else: + if line.subcontractor_work_ids: + line.invalid_work_amount = line.price_subtotal + else: + line.invalid_work_amount = False + + def _check_in_invoice_amount(self): + return ( + abs(self.subcontractor_work_invoiced_id.cost_price - self.price_subtotal) + > 0.1 + ) + + def _check_out_invoice_amount(self): + # TODO FIXME + if self.move_id.company_id.id != 1: + # this mean Akretion + if self.move_id.partner_id.id == 1: + return ( + abs( + self.subcontractor_work_invoiced_id.cost_price + - self.price_subtotal + ) + > 0.1 + ) + else: + subtotal = sum(self.subcontractor_work_ids.mapped("sale_price")) + # we use a bigger diff to avoid issue with rounding + return abs(subtotal - self.price_subtotal) > 0.1 + + @api.model + def _prepare_account_move_line(self, dest_invoice, dest_company): + res = super()._prepare_account_move_line(dest_invoice, dest_company) + res["subcontractor_work_invoiced_id"] = self.subcontractor_work_invoiced_id.id + return res + + def edit_subcontractor(self): + view = { + "name": ("Details"), + "view_type": "form", + "view_mode": "form", + "res_model": "account.move.line", + "view_id": self.env.ref( + "account_invoice_subcontractor.view_move_line_subcontractor_form" + ).id, + "type": "ir.actions.act_window", + "target": "new", + "res_id": self.id, + } + return view + + @api.onchange("quantity") + def _onchange_quantity(self): + for line in self: + if len(line.subcontractor_work_ids) == 1: + line.subcontractor_work_ids.quantity = line.quantity diff --git a/account_invoice_subcontractor/models/hr.py b/account_invoice_subcontractor/models/hr_employee.py similarity index 96% rename from account_invoice_subcontractor/models/hr.py rename to account_invoice_subcontractor/models/hr_employee.py index 145981d..b7cfece 100644 --- a/account_invoice_subcontractor/models/hr.py +++ b/account_invoice_subcontractor/models/hr_employee.py @@ -20,7 +20,6 @@ def _get_subcontractor_type(self): "res.company", string="Subcontractor Company" ) subcontractor_type = fields.Selection( - string="Subcontractor Type", selection="_get_subcontractor_type", required=True, default="internal", diff --git a/account_invoice_subcontractor/models/product.py b/account_invoice_subcontractor/models/product_template.py similarity index 100% rename from account_invoice_subcontractor/models/product.py rename to account_invoice_subcontractor/models/product_template.py diff --git a/account_invoice_subcontractor/models/sale.py b/account_invoice_subcontractor/models/sale.py deleted file mode 100644 index 43312e6..0000000 --- a/account_invoice_subcontractor/models/sale.py +++ /dev/null @@ -1,12 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import models - - -class SaleOrderLine(models.Model): - _inherit = "sale.order.line" - - def _prepare_invoice_line(self, **optional_values): - vals = super()._prepare_invoice_line(**optional_values) - vals["subcontracted"] = self.product_id.subcontracted or False - return vals diff --git a/account_invoice_subcontractor/models/subcontractor_work.py b/account_invoice_subcontractor/models/subcontractor_work.py index f319c7a..2e590a8 100644 --- a/account_invoice_subcontractor/models/subcontractor_work.py +++ b/account_invoice_subcontractor/models/subcontractor_work.py @@ -63,7 +63,12 @@ def _get_subcontractor_type(self): string="Supplier Invoice Date", store=True, ) - quantity = fields.Float(digits="Product Unit of Measure") + quantity = fields.Float( + digits="Product Unit of Measure", + compute="_compute_quantity", + store=True, + readonly=False, + ) sale_price_unit = fields.Float( compute="_compute_price", digits="Account", store=True ) @@ -105,7 +110,9 @@ def _get_subcontractor_type(self): compute="_compute_state", selection=INVOICE_STATE, store=True, compute_sudo=True ) subcontractor_type = fields.Selection( - string="Subcontractor Type", selection="_get_subcontractor_type" + selection="_get_subcontractor_type", + compute="_compute_subcontractor_type", + store=True, ) state = fields.Selection( compute="_compute_state", @@ -120,38 +127,6 @@ def _get_subcontractor_type(self): store=True, string="Unit", ) - # same_fiscalyear = fields.Boolean() - # # We keep the data here - # # compute='_check_same_fiscalyear', - # # store=True, - # # compute_sudo=True) - # min_fiscalyear = fields.Char() - # # compute='_check_same_fiscalyear', - # # store=True, - # # compute_sudo=True) - - # # - # # @api.depends( - # # 'invoice_line_id.invoice_id.date_invoice', - # # 'supplier_invoice_line_id.invoice_id.date_invoice') - # # def _check_same_fiscalyear(self): - # # fyo = lf.env['account.fiscalyear'] - # # for sub in self: - # # invoice_year_id = fyo.find( - # # sub.invoice_line_id.invoice_id.date_invoice) - # # supplier_invoice_year_id = fyo.find( - # # sub.supplier_invoice_line_id.invoice_id.date_invoice) - # # sub.same_fiscalyear = invoice_year_id == supplier_invoice_year_id - # # invoice_year = fyo.browse(invoice_year_id) - # # supplier_invoice_year = fyo.browse(supplier_invoice_year_id) - # # if invoice_year and supplier_invoice_year: - # # sub.min_fiscalyear = min( - # # invoice_year.name, - # # supplier_invoice_year.name) - # # else: - # # sub.min_fiscalyear = max( - # # invoice_year.name, - # # supplier_invoice_year.name) def _get_commission_rate(self): company = self.invoice_line_id.company_id or self.env.company @@ -169,7 +144,11 @@ def _get_commission_rate(self): def _compute_price(self): for work in self: line = work.invoice_line_id - sale_price_unit = line.price_unit * (1 - line.discount / 100.0) + # Better this way to be sure to manage all cases ? For instance if + # we got a tax included in price unit, we do not want it and we had it + # in previous way. Maybe it will give us worse rounding issue though + sale_price_unit = line.price_subtotal / line.quantity + # sale_price_unit = line.price_unit * (1 - line.discount / 100.0) rate = 1 if not work.invoice_line_id.product_id.no_commission: rate -= work._get_commission_rate() @@ -179,14 +158,16 @@ def _compute_price(self): work.cost_price = work.quantity * work.cost_price_unit work.sale_price = work.quantity * work.sale_price_unit - @api.onchange("employee_id") - def employee_id_onchange(self): - self.ensure_one() - if self.employee_id: - self.subcontractor_type = self.employee_id.subcontractor_type - line = self.invoice_line_id - # TODO find a good way to get the right qty - self.quantity = line.quantity + @api.depends("employee_id") + def _compute_quantity(self): + for rec in self: + rec.quantity = self.invoice_line_id.quantity + + @api.depends("employee_id") + def _compute_subcontractor_type(self): + for rec in self: + if rec.employee_id: + rec.subcontractor_type = rec.employee_id.subcontractor_type @api.depends( "invoice_line_id", @@ -218,8 +199,8 @@ def check(self, work_type=False): if dest_invoice_company not in self.env.companies: raise UserError( _( - "You can't generate an invoice for a company you have no access : %s" - % dest_invoice_company.name + "You can't generate an invoice for a company you have no access" + " : %s" % dest_invoice_company.name ) ) if partner_id != work.customer_id.id: @@ -259,7 +240,8 @@ def _prepare_invoice(self): if orig_invoice.move_type not in ("out_invoice", "out_refund"): raise UserError( _( - "You can only invoice the subcontractors on a customer invoice/refund" + "You can only invoice the subcontractors on a customer " + "invoice/refund" ) ) company = self._get_dest_invoice_company() @@ -300,23 +282,25 @@ def _prepare_invoice(self): ) if not journal: raise UserError( - _('Please define %s journal for this company: "%s" (id:%d).') - % (journal_type, company.name, company.id) + _( + "Please define %(journal_type)s journal for this company: " + "'%(company_name)s' (id:%(company_id)d)." + ) + % { + "journal_type": journal_type, + "company_name": company.name, + "company_id": company.id, + } ) - invoice_vals = {"partner_id": partner.id, "move_type": invoice_type} - invoice_vals = self.env["account.move"].play_onchanges( - invoice_vals, ["partner_id"] - ) - invoice_vals.update( - { - "invoice_date": invoice_date, - "partner_id": partner.id, - "journal_id": journal.id, - "invoice_line_ids": [(6, 0, [])], - "currency_id": company.currency_id.id, - "user_id": user.id, - } - ) + invoice_vals = { + "invoice_date": invoice_date, + "move_type": invoice_type, + "partner_id": partner.id, + "journal_id": journal.id, + "invoice_line_ids": [(6, 0, [])], + "currency_id": company.currency_id.id, + "user_id": user.id, + } if invoice_type in ["out_invoice", "out_refund"]: invoice_vals["origin_customer_invoice_id"] = orig_invoice.id return invoice_vals @@ -324,11 +308,10 @@ def _prepare_invoice(self): @api.model def _prepare_invoice_line(self, invoice): self.ensure_one() - invoice_line_obj = self.env["account.move.line"] line_vals = { "product_id": self.sudo().invoice_line_id.product_id.id, "quantity": self.quantity, - "name": "Client final {} :{}".format(self.end_customer_id.name, self.name), + "name": f"Client final {self.end_customer_id.name} :{self.name}", "price_unit": self.cost_price_unit, "move_id": invoice.id, "subcontractor_work_invoiced_id": self.id, @@ -343,8 +326,6 @@ def _prepare_invoice_line(self, invoice): "end_date": self.sudo().invoice_line_id.end_date, } ) - onchange_vals = invoice_line_obj.play_onchanges(line_vals, ["product_id"]) - line_vals.update(onchange_vals) return line_vals def _get_subcontractor_invoicing_group(self): @@ -421,16 +402,6 @@ def _scheduler_action_subcontractor_invoice_create(self): for subcontractor in subcontractors: dest_company = subcontractor.subcontractor_company_id user = subcontractor.user_id - # # TOFIX - # old_company = False - # if user.company_id != dest_company: - # if dest_company.id in user.company_ids.ids: - # old_company = user.company_id - # user.company_id = subcontractor.subcontractor_company_id - # else: - # user = self.env["res.users"].search( - # [("company_id", "=", dest_company.id)], limit=1 - # ) subcontractor_works = ( self.with_user(user) .with_company(dest_company) @@ -441,10 +412,9 @@ def _scheduler_action_subcontractor_invoice_create(self): ], ) ) - _logger.info( - "%s lines found for subcontractor %s" - % (subcontractor_works.ids, subcontractor.name) - ) + sub_ids = subcontractor_works.ids + sub_name = subcontractor.name + _logger.info(f"{sub_ids} lines found for subcontractor {sub_name}") invoices = subcontractor_works.invoice_from_work() for invoice in invoices: invoice.action_post() diff --git a/account_invoice_subcontractor/tests/test_subcontractor_invoice.py b/account_invoice_subcontractor/tests/test_subcontractor_invoice.py index 726eecf..ac814c9 100644 --- a/account_invoice_subcontractor/tests/test_subcontractor_invoice.py +++ b/account_invoice_subcontractor/tests/test_subcontractor_invoice.py @@ -18,8 +18,10 @@ def setUpClass(cls): cls.invoice_obj = cls.env["account.move"] # configure subcontracted product - cls.product_consultant_multi_company.write({"subcontracted": True}) - cls.product_consultant_multi_company.sudo(cls.user_company_b.id).write( + cls.product_consultant_multi_company.with_user(cls.user_company_a.id).write( + {"subcontracted": True} + ) + cls.product_consultant_multi_company.with_user(cls.user_company_b.id).write( {"property_account_income_id": cls.a_sale_company_b.id} ) @@ -75,6 +77,9 @@ def test_customer_subcontractor(self): """Company A sell stuff to customer B but subcontract it to company B""" # ensure our user is in company A self.env.user.company_id = self.company_a.id + self.env.user.write( + {"groups_id": [(4, self.env.ref("account.group_account_user").id)]} + ) invoice = Form( self.account_move_obj.with_company(self.company_a.id).with_context( @@ -101,9 +106,6 @@ def test_customer_subcontractor(self): "employee_id": self.employee_b.id, "invoice_line_id": invoice_line.id, } - sub_work_vals = self.env["subcontractor.work"].play_onchanges( - sub_work_vals, ["employee_id"] - ) subwork = self.env["subcontractor.work"].create(sub_work_vals) self.assertEqual(subwork.quantity, 2) self.assertEqual(subwork.sale_price_unit, 200) diff --git a/account_invoice_subcontractor/views/invoice_view.xml b/account_invoice_subcontractor/views/account_move_line_view.xml similarity index 54% rename from account_invoice_subcontractor/views/invoice_view.xml rename to account_invoice_subcontractor/views/account_move_line_view.xml index 98e8dad..6603290 100644 --- a/account_invoice_subcontractor/views/invoice_view.xml +++ b/account_invoice_subcontractor/views/account_move_line_view.xml @@ -37,108 +37,6 @@ --> - - account.move - - -
-
- - - - - - - - - - - - - invalid_work_amount == True - - - {'readonly': 0} - - - - - - -