-
Notifications
You must be signed in to change notification settings - Fork 23.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] project: create projects linked to company-specific customer #162961
base: saas-16.4
Are you sure you want to change the base?
[FIX] project: create projects linked to company-specific customer #162961
Conversation
63dd145
to
86aaca8
Compare
This fix changes the internal logic more than I'd like ideally, but I think we're a bit stuck if we want the
|
There is currently a task for the R&D team to solve this behaviour (3757184) |
940888a
to
d78a8dc
Compare
Another possible fix if we do want the analytic account's odoo/addons/project/models/project_project.py Line 855 in d78a8dc
+ save_company = False
+ if not company and (partner_id := values.get('partner_id')):
+ partner = self.env['res.partner'].browse(partner_id)
+ save_company = partner.company_id
+ partner.write({'company_id': False})
analytic_account = self.env['account.analytic.account'].create({
'name': values.get('name', _('Unknown Analytic Account')),
'company_id': company.id,
'partner_id': values.get("partner_id", False),
'plan_id': plan.id,
})
+ if save_company:
+ partner.write({'company_id': save_company.id}) Where the idea is that we temporarily unset the partner's company to circumvent the check. I think with this fix the runbot is fully green without having to editing existing tests, but I'm not choosing it as a first choice because of the code smell. Also in this case we probably also need to somehow ensure the analytic account's partner is set alongside the project's if we want to be consistent. Yet again a 3rd possibility would be to enforce the constraint that the project's company has to match its partner's. |
1eab0b4
to
e143298
Compare
Problem --- When creating projects with a customer whose company field is set, `_check_company` raises an Error because of a mismatch with the analytic account's company (False). Steps --- (from fresh db, with demo data) 1. install `project` and `sale_management` (so that projects can be billable) 2. in the settings, create a second company, (so that contacts' 'Company' field can be set) 3. on a contact, set the 'Company' field (under: Sales & Purchase > Misc) to the current company ('YourCompany') 4. In Setting > Project: enable 'Timesheets' 5. Try to create a new billable project with 'Timesheets' enabled and the customer from step 3 Fix --- Never set the partner on the analytic account when creating a new project. Note that we have to modify the corresponding test. This is acceptable because in some flows (create project with no partner, **then** set the partner) this is what already happens and seems to not be a problem. opw-3865150
e143298
to
ebe8b65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @naja628,
I think the different solutions can work (it's up to the R&D team to decide which one suits them best).
The solution of not setting the partner on the analytic_account
(current diff) may be radical, but it allows us to fallback on the behavior we know when we create a project and set the partner afterwards.
The second solution, to remove the company and then put it back, bypasses the company check, but I don't think it's a good practice.
The third solution of reinforcing the constraint may not be the best solution for stable versions.
@xavierbol What do you think ?
@xavierbol Hello :) |
[FIX] project,hr_timesheet: create projects with company-specific customer
Problem
When creating projects with a customer whose company field is set,
_check_company
raises an Error because of a mismatch withthe analytic account's company (False).
Steps
(from fresh db, with demo data)
project
andsale_management
(so that projects can bebillable)
(so that contacts' 'Company' field can be set)
to the current company ('YourCompany')
and the customer from step 3
Fix
Never set the partner on the analytic account when creating a new
project.
Note that we have to modify the corresponding test.
This is acceptable because in some flows (create project with
no partner, then set the partner) this is what
already happens and seems to not be a problem.
opw-3865150
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr