Merge lp:~openerp-dev/openobject-server/7.0-opw-591308-jam into lp:openobject-server/7.0
- 7.0-opw-591308-jam
- Merge into 7.0
Status: | Merged |
---|---|
Merged at revision: | 5070 |
Proposed branch: | lp:~openerp-dev/openobject-server/7.0-opw-591308-jam |
Merge into: | lp:openobject-server/7.0 |
Diff against target: |
51 lines (+22/-1) 2 files modified
openerp/addons/base/res/res_partner.py (+10/-0) openerp/addons/base/res/res_users.py (+12/-1) |
To merge this branch: | bzr merge lp:~openerp-dev/openobject-server/7.0-opw-591308-jam |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nhomar - Vauxoo (community) | Approve | ||
Moisés López - http://www.vauxoo.com (community) | Needs Information | ||
Stefan Rijnhart (Opener) (community) | Approve | ||
Maxime Chambreuil (http://www.savoirfairelinux.com) (community) | tests | Approve | |
Rifakat Husen (OpenERP) (community) | Needs Resubmitting | ||
Jigar A. (community) | Needs Resubmitting | ||
Olivier Dony (Odoo) | Needs Fixing | ||
Naresh(OpenERP) | Pending | ||
Review via email: mp+158311@code.launchpad.net |
Commit message
Description of the change
OPW#591308 :User's partner company is by default company_id of a user who created the user instead of new created user's company.
Test Case:
- Database without Demonstration Records installed.
- Login with Default Admin(root) login user.
- Create a New Independent Company "Second Company".
- Create a New Admin user "Second Admin" for the New Company Created above with allowed "Second Company".
Problem : Above Operation will create the New Partner for The User "Second Admin" with Company set to the "Your Company" which is currently logged in user company. Which is Wrong.
Expected : For user partner Company must be uses Company not logged in user company (so I above case Partner Compnay should be "Second Company" instead of "Your Company").
Problem : If I change the Company of the User "Second Admin" and Save it does not updates the Company of the "Second Admin" Partner.
Expected : If I change the Company of the User "Second Admin" and Save it, it should change Company of partner "Second Admin" to new company set on user.
Kindly review the code.
Thank You
- 4929. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4930. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4931. By Quentin (OpenERP) <email address hidden>
-
[FIX] module, technical reference guide report: print only the that have been added, not all the fields of the modified objects
- 4932. By Quentin (OpenERP) <email address hidden>
-
[FIX] res_bank: good naming of the keyword parameters of fields_get()
- 4933. By Quentin (OpenERP) <email address hidden>
-
[FIX] module, technical reference guide report: don't print fields having the same name than another on another object that have been modified in that module. + small refactoring
- 4934. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4935. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4936. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4937. By Xavier (Open ERP)
-
[FIX] incorrect view in super() call
super() finds the MRO parent of the provided class to resume the
execution chain from there, so the class being defined should be
provided.Here view called super(osv.osv, self).create so if osv.osv (Model) had
a create() defined (which luckily it does not) it would've been
skipped. - 4938. By Christophe Simonis (OpenERP)
-
[FIX] typo in method name in apps.js
- 4939. By Olivier Dony (Odoo)
-
[MERGE] res.partner, orm._check_
recursion: prevent recursive partner structures + fix false positives in check_recursion() - res.partner must prevent creating loops in partner
hierarchies, and this can be done easily with an
extra _constraint using the ORM's builtin _check_recursion- _check_recursion's implementation incorrectly
assumed that the provided 'ids' were unrelated
(not part of a common hierarchy).- add tests for _check_recursion via extra
tests on res.partner structure
(explains why both patches are in the same
commit) - 4940. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4941. By Stephane Wirtel (OpenERP)
-
[MERGE] After the installation, reload the Apps interface if the modules are not
on the local repo of the addons. - 4942. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4943. By Quentin (OpenERP) <email address hidden>
-
[FIX] base, res_company: added a missing context when calling write(), apparently needed for OPW: 586824
- 4944. By Antony Lesuisse (OpenERP)
-
[FIX] ir.cron add a safeguard mecanism against version mistach when polling
- 4945. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4946. By Olivier Dony (Odoo)
-
[MERGE] res.partner: many important fixes for contact/company management and address management, see bug 1160365
- Fix autosync of accounting/
invoicing- related fields on contacts, just as if they were actually modeled as fields.related to the parent commercial entity. This starts with the addition of the new functional field `commercial_ partner_ id`, to locate the commercial entity for any partner. The commercial entity is defined as the first ancestor (starting at the partner itself) that is either marked `is_company` or has no parent. - Corrected autosync of address fields (bug 1160425). Also included in the same patch, because those two mechanisms are closely related and share some parts of the implementation. "use_parent_
address" now defaults to False, and auto-sync only happens downstream, except for a special case when creating a new company and a new contact at the same time - `is_company` does not reset the parent_id field anymore, to allow for multi-level structures. The `parent_id` field now also stays visible if it has a non-empty value
- the `email`, `phone`, `fax`, `mobile`, `lang`, etc. that were sometimes synced when changing parent company are now properly left alone
- res.partner.
address_ get() now defaults to the partner being looked up rather than company when no match is found at all and no "default" exists. This avoids losing the contact info on invoices when a new contact+company pair is created. - the embedded contact creation mini-form was updated to include the address fields and the `type` field
- res.partner.
name_get now return "Company, Contact" rather than "Contact (Company)" to make it clearer that the company is selected as well. - Added warning message when changing the Company of a Contact that already has a company, so it is clear that it should only be done if the Company was incorrect - in other cases a new contact must be created under the new company.
- Fixed search domains using "child_of" to also include deactived records, so that using this operator in the search view of business documents returns the expected results.
- fixed propagation of "is_supplier" flag when creation a parent company for a contact created on the fly on a Purchase Order, and when adding contacts to an existing Supplier Company
- 4947. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4948. By Quentin (OpenERP) <email address hidden>
-
[FIX] orm, _generate_
order_by( ): allow to order by LOG_ACCESS_COLUMNS even if the column is not defined again in self._columns. Raising an error instead of silently skipping the order_by - 4949. By Quentin (OpenERP) <email address hidden>
-
[FIX] ir_sequence: the field company_id does not exist in res.company, and thus cannot be used as sorting criterion in search()
- 4950. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4951. By Olivier Dony (Odoo)
-
[FIX] rml2html: incorrect license headers in some source files, reported and contributed by Alec Leamas
Mixing LGPL 2.1 and AGPL 3.0 in the same source file
is incorrect, and the AGPLv3 license was added by
mistake: keep only LGPL license and preserve
copypright info. - 4952. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4953. By Quentin (OpenERP) <email address hidden>
-
[IMP/FIX] ir_model_data: added check_object_
reference( ) in order to return a value only if the uid has read access on the targeted object. It avoids raising access rights errors further in the process and prevents duplicating that same code in all addons - 4954. By Christophe Simonis (OpenERP)
-
[FIX] expression: allow creating child_of expression even if "id" field has been redefined, courtesy of Gustavo Adrian Marino
- 4955. By Antony Lesuisse (OpenERP)
-
[FIX] workers, listen backlog based on the number of workers
- 4956. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4957. By Quentin (OpenERP) <email address hidden>
-
[REV] revert of commit 4953 that was not appropriate for a stable version. Will be back in trunk
- 4958. By Olivier Dony (Odoo)
-
[FIX] res.partner: always call write() with a list of IDs, a single ID is not valid! (even if it works sometimes)
- 4959. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4960. By Olivier Dony (Odoo)
-
[FIX] res.partner: make use_parent_address field visible if set, even if parent is missing
This should not be needed but in the initial 7.0 branch
the default for use_parent_address was True so it was
set even on partners that had no parent company.
Now that the fields are read-only when that option
is enabled, it makes the address impossible to
edit. At least by making it visible we give the
user the opportunity of fixing it manually.Can also be fixed at once with a single SQL
query:
UPDATE res_partner set use_parent_address = false
WHERE parent_id IS NULL; - 4961. By Olivier Dony (Odoo)
-
[FIX] res.partner: typo would prevent contact from using company address correctly if flag changed without changing/setting company + updated tests to cover this
- 4962. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4963. By Thibault Delavallée (OpenERP)
-
[FIX] Fix needaction counters, now updated dynamically.
server branch: when reloading the needaction of some menus, also
reload those of related menus. Related menus are defined in the
context of the action associated with the menu, in a
needaction_menu_ref key that is a list of menu xml_ids. - 4964. By Olivier Dony (Odoo)
-
[FIX] rml2pdf: more incorrect license headers in some source files, reported by Alec Leamas
Mixing LGPL 2.1 and AGPL 3.0 in the same source file
is incorrect, and the AGPLv3 license was added by
mistake: keep only LGPL license and preserve
copypright info. - 4965. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4966. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4967. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4968. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4969. By Quentin (OpenERP) <email address hidden>
-
[IMP] modules loading: log as INFO test files because, if they are logged as TEST, the loading statement get lost in the mass of real TEST logs in case there are a lot of test files (more visible that way) + there are no reason to special case these files
- 4970. By Olivier Dony (Odoo)
-
[FIX] ir.ui.menu: safer eval of action contexts when computing needaction
Unchecked eval of a context may fail for various reasons,
such as the use of client-side variables like `active_id` - 4971. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4972. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
Jigar A. (ifixthat) wrote : | # |
@Olivier Dony, Thank You for review,
I do agree with with your functional and technical notes on this and have fixed the code according.
kindly give a look to the improvements,
Thanks.
- 4973. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4974. By Martin Trigaux (OpenERP)
-
[MERGE] correct permissions, shebang, EOL and FSF address
- 4975. By Quentin (OpenERP) <email address hidden>
-
[FIX] base: moving the old timezone formats at the end of selection list to avoid confusing users
- 4976. By Olivier Dony (Odoo)
-
[FIX] openerp/
tests/test_ mail.py marked executable as it should - 4977. By Olivier Dony (Odoo)
-
[MERGE] res.currency: default to global currencies in multi-company setup + add proper ir.rule, courtesy of Alexandre Fayolle (Camptocamp)
- 4978. By Olivier Dony (Odoo)
-
[MERGE] ir.sequence: lazily compute next value for PostgreSQL-backed ir.sequences + avoid resetting it at each change to the sequence, courtesy of Ronald Portier (Therp)
The original patch proposed by Ronald has been modified to
make it more suitable to a stable version, in the following
aspects:
- remove all extra physical columns (boolean flags), as they
would break the stable policy and were actually unnecessary
to fix the bug
- avoid displaying both the number_next and the number_next_actual,
the latter is sufficient
- fix a possible bug when setting the number_next to 0 - 4979. By Olivier Dony (Odoo)
-
[FIX] ir.sequence: add a proper default value for number_next_actual (0 is disallowed by default) + avoid error when trying to alter a sequence during creation
- 4980. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4981. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4982. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4983. By Martin Trigaux (OpenERP)
-
[IMP] remove read access to outgoing mail server configuration
forward port of rev 4349 in 6.1 - 4984. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4985. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4986. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4987. By Quentin (OpenERP) <email address hidden>
-
[FIX] report, rlm2pdf: added support of Sun-ExtA font and the possibility to define a default value for font parameters in parastyles. We can now use <paraStyle name='Normal fontName='xxxx'/> in company header, for example, if we want to define font xxxx to be used by default in each rml reports (if not overwritten in a further paraStyle)
- 4988. By Quentin (OpenERP) <email address hidden>
-
[IMP/FIX] base, res_company: changed the default headers in order to add the default styles in generated RML, to allow their modification (and the report printing of chinese characters, for example)
- 4989. By Christophe Simonis (OpenERP)
-
[FIX] rml2pdf: correct filename for Sun-ExtA font
- 4990. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4991. By Thibault Delavallée (OpenERP)
-
[MERGE] [CHERRYPICK] Backport of revision 4879 of saas-1 branch.
[FIX] ir_attachment: in check, values could coutain a
False res_model; no need to check self.pool[False], obviously. We consider void attachments
as being accessible, because no related document exists. - 4992. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4993. By Quentin (OpenERP) <email address hidden>
-
[FIX] base, res_company: typo in default paraStyle tagname
- 4994. By Quentin (OpenERP) <email address hidden>
-
[IMP/FIX] report, trml2pdf: added the support of registerFontFamily tag to allow the mapping of different fonts for bold, italic or boldItalic
- 4995. By Quentin (OpenERP) <email address hidden>
-
[FIX] trml2pdf: reportlab 2.4.4 doesn't support the previous syntax (sname in self.default_style)
- 4996. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4997. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 4998. By Olivier Dony (Odoo)
-
[MERGE] base: remove remaining company assignments on currencies, courtesy of Stefan Rijnhart (Therp)
Fix of the testsuite (in openerp/
addons/ base/test/ test_osv_ expression. yml)
done on top of Stefan's original patch - 4999. By Christophe Matthieu (OpenERP)
-
[IMP] Improve typos in warning (Grammar mistake, Capitalize title, Typos)
- 5000. By Olivier Dony (Odoo)
-
[MERGE] [I18N] Many translation bugfixes + resync of translation templates with latest source
- 5001. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5002. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
Moisés López - http://www.vauxoo.com (moylop260) wrote : | # |
We tested it
Done!
You will merge it?
- 5003. By Martin Trigaux (OpenERP)
-
[MERGE] [FIX] res.users: prevent exporting the virtual 'Access Rights' fields
A corresponding patch on openerp-web takes that
new field attribute into account
Olivier Dony (Odoo) (odo-openerp) wrote : | # |
I have some more remarks:
l.12: redundant test
l.12-18: that code does not prevent changing the partner company to something different from the user's company, as far as I can tell? The error message illustrates this. The comment is correct but does not match the code.
l.15-16: why not use the res.partner.
Thanks :-)
Jigar A. (ifixthat) wrote : | # |
Hello,
Thanks for review and Correction which I have done according, and committed changes here. Kindly review them.
Thank you
- 5004. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5005. By Olivier Dony (Odoo)
-
[FIX] res.partner: name_search() should match complete contact names in the format returned by name_get()
This was missed during the change of the name_get()
format at revision 4923.1.12
revid:<email address hidden> - 5006. By Christophe Simonis (OpenERP)
-
[FIX] correct stripping of arguments when _reexec() OpenERP
- 5007. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5008. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5009. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5010. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5011. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5012. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5013. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5014. By Olivier Dony (Odoo)
-
[FIX] OPW 592482: browse_record should not prefetch binary fields
This was apparently a long-standing issue due to a
strange handling of the _prefetch attribute on
columns: accessing a column would only trigger
the prefetching if its _prefetch attribute was
True, but the prefetching itself would also
prefetch columns that had _prefetch False.We clearly want it the other way around, or
at least we want _prefetch to decide whether
a column is included in any given prefetching
pass. We can skip the prefetching pass when
the only field being accessed has _prefetch
False because it is likely the other fields
have already been prefetched separately.
This last subtlety should not make any
noticeable performance difference. - 5015. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5016. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5017. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5018. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5019. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5020. By Vo Minh Thu
-
[MERGE] lang: added Amharic (Ethiopia) language.
The corresponding web branch was merged in january.
- 5021. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5022. By Olivier Dony (Odoo)
-
[FIX] ir.translation: backport of trunk fix to allow editing master english source terms
Original trunk commits rev-ids:
- 4855 <email address hidden>
- 4856 <email address hidden>
- 4857 <email address hidden>
Moisés López - http://www.vauxoo.com (moylop260) wrote : | # |
Hello, Will You merge this merge into 7.0?
- 5023. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5024. By Olivier Dony (Odoo)
-
[FIX] ir.ui.view: properly validate newly created inheriting views
When a new inheriting view is imported during a module
installation, it is validated thanks to the _constraints
on the ir.ui.view model. However the validation uses
a rather convoluted system for validating the whole
view tree at once (root view + all inherited changes)
while only taking into account the views that belong
to modules that are currently loaded.This complicated system is necessary to be able to
operate on-the-fly at any point during the registry
loading/initialization. Now because _constraints are checked during create()
this particular validation happens *before* the
external ID (ir.model.data entry) of that new view
can be created (it obviously needs to wait until
the view record is inserted). As a consequence the
view validation cannot determine the module to
which that new view belongs, and was erroneously
ignoring it.
Changing the view filtering to also include views
from unknown modules fixes this transient problem,
and also means that manually created inherited
views will be validated during module init too. - 5025. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5026. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote : | # |
Can someone merge this MP please ?
Thank you.
- 5027. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5028. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5029. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5030. By Christophe Simonis (OpenERP)
-
[FIX] expression: a valid leaf must have a non empty string as first element or be the magic TRUE_LEAF/
FALSE_LEAF - 5031. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5032. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5033. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5034. By Christophe Simonis (OpenERP)
-
[IMP] WorkerCron: make the cron workers not all starting at the first database. Better repartition of work
[IMP] WorkerCron: renice processBackport of commits 4891 <email address hidden> and 4892 <email address hidden>
of saas-1 branch - 5035. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
Stefan Rijnhart (Opener) (stefan-opener) wrote : | # |
As Willem Hulshof remarked on the bug thread, it is not possible to create a database anymore with rev. 4933 merged in your setup. The database creation breaks at assigning the main company to the main partner.
In fact, in an existing database you cannot create a new partner without a company, then edit the user and assign a company to it. It will lead to the same error, "You can not change the company as the partner/user has mutiple user linked with different companies.".
Seems easy to fix by checking if the partner is associated with any users at all in line 15 or 16.
Stefan Rijnhart (Opener) (stefan-opener) wrote : | # |
Sorry, meant to say "you cannot create a new partner without a company, then edit the *partner* and assign a company to it"
- 5036. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5037. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5038. By Launchpad Translations on behalf of openerp
-
Launchpad automatic translations update.
- 5039. By Martin Trigaux (OpenERP)
-
[FIX] report: force encoding of dateformat string
some locales have unicode into the date format (eg: zh_CN uses %Y年%m月%d日)
conversion using str() would not work for them
opw #593932 - 5040. By Olivier Dony (Odoo)
-
[FIX] ir.model: during creation of custom models, the _auto_init call should also take care of custom fields created on-the-fly
The _auto_init call in ir.model.fields creation will not
do it because it happens before the insertion of the model
in the registry. It will only work for later addition of
fields. - 5041. By Martin Trigaux (OpenERP)
-
[FIX] res_currency: allow silent failing for computation of current rate if no rate exists, allow accessing the tree and form view if incorrectly configured currency
- 5042. By Rifakat Husen (OpenERP)
-
[FIX] fix demo data problem, now able to assign company to existing partner which does not have
any company. Did small variable name change - 5043. By Rifakat Husen (OpenERP)
-
[IMP] removed unused user pool
Rifakat Husen (OpenERP) (rha-openerp) wrote : | # |
Thanks Stefan, you are right.
I have just updated the fix on rev 5042 and 5043, could you please check?
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) : | # |
Stefan Rijnhart (Opener) (stefan-opener) wrote : | # |
Thanks Rifakat! I verified that your latest version solves the problem that we observed.
Moisés López - http://www.vauxoo.com (moylop260) wrote : | # |
What is the status with this MP?
Nhomar - Vauxoo (nhomar) wrote : | # |
Hello Status of this MP, Some news?
Serpent Consulting Services (serpent-consulting-services) wrote : | # |
Merged! Great! RIP the bug!
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote : | # |
Yeah! Thank you!
Moisés López - http://www.vauxoo.com (moylop260) wrote : | # |
Yes!!
Thank you!
Preview Diff
1 | === modified file 'openerp/addons/base/res/res_partner.py' |
2 | --- openerp/addons/base/res/res_partner.py 2013-06-12 09:53:00 +0000 |
3 | +++ openerp/addons/base/res/res_partner.py 2013-08-01 06:41:27 +0000 |
4 | @@ -489,6 +489,16 @@ |
5 | def write(self, cr, uid, ids, vals, context=None): |
6 | if isinstance(ids, (int, long)): |
7 | ids = [ids] |
8 | + #res.partner must only allow to set the company_id of a partner if it |
9 | + #is the same as the company of all users that inherit from this partner |
10 | + #(this is to allow the code from res_users to write to the partner!) or |
11 | + #if setting the company_id to False (this is compatible with any user company) |
12 | + if vals.get('company_id'): |
13 | + for partner in self.browse(cr, uid, ids, context=context): |
14 | + if partner.user_ids: |
15 | + user_companies = set([user.company_id.id for user in partner.user_ids]) |
16 | + if len(user_companies) > 1 or vals['company_id'] not in user_companies: |
17 | + raise osv.except_osv(_("Warning"),_("You can not change the company as the partner/user has multiple user linked with different companies.")) |
18 | result = super(res_partner,self).write(cr, uid, ids, vals, context=context) |
19 | for partner in self.browse(cr, uid, ids, context=context): |
20 | self._fields_sync(cr, uid, partner, vals, context) |
21 | |
22 | === modified file 'openerp/addons/base/res/res_users.py' |
23 | --- openerp/addons/base/res/res_users.py 2013-06-07 09:30:57 +0000 |
24 | +++ openerp/addons/base/res/res_users.py 2013-08-01 06:41:27 +0000 |
25 | @@ -279,6 +279,13 @@ |
26 | |
27 | return result |
28 | |
29 | + def create(self, cr, uid, vals, context=None): |
30 | + user_id = super(res_users, self).create(cr, uid, vals, context=context) |
31 | + user = self.browse(cr, uid, user_id, context=context) |
32 | + if user.partner_id.company_id: |
33 | + user.partner_id.write({'company_id': user.company_id.id}) |
34 | + return user_id |
35 | + |
36 | def write(self, cr, uid, ids, values, context=None): |
37 | if not hasattr(ids, '__iter__'): |
38 | ids = [ids] |
39 | @@ -293,7 +300,11 @@ |
40 | uid = 1 # safe fields only, so we write as super-user to bypass access rights |
41 | |
42 | res = super(res_users, self).write(cr, uid, ids, values, context=context) |
43 | - |
44 | + if 'company_id' in values: |
45 | + for user in self.browse(cr, uid, ids, context=context): |
46 | + # if partner is global we keep it that way |
47 | + if user.partner_id.company_id and user.partner_id.company_id.id != values['company_id']: |
48 | + user.partner_id.write({'company_id': user.company_id.id}) |
49 | # clear caches linked to the users |
50 | self.pool.get('ir.model.access').call_cache_clearing_methods(cr) |
51 | clear = partial(self.pool.get('ir.rule').clear_cache, cr) |
Hello,
I agree with the patch, we indeed need to make sure that the company of the partner from which each user inherits is the same company as the company of the user.
This is a bit strange because the user may change their company from their preferences at any time, and this will also propagate the change to the partner record, but there's no easy way to prevent that. Changing the record rules like suggested in comment #68 of bug 1073087 would help but it would not fix 100% cases, for example there are cases where the partner company is used indirectly (e.g. for mail messages etc.)
I have a few functional and technical remarks about the patch:
Functionally id.company_ id and user.partner_ id.company_ id != new_company_id`. That way we allow keeping partner.company_id to False.
------------
- We should allow setting the company_id of the partner to False in order to make the partner shared between all companies (the company_id field is not required on res.partner). So res_users.write() must only write to the partner if `user.partner_
- The synchronization must be managed carefully from the partner side as well. The write() method of res.partner must only allow to set the company_id of a partner if it is the same as the company of all users that inherit from this partner (this is to allow the code from res_users to write to the partner!) or if setting the company_id to False (this is compatible with any user company).
- This code does not take care of fixing all existing records which have a problem. We should also provide SQL queries to execute on customer databases to fix the existing records:
-- To show the partners with this issue
SELECT p.id AS partner_id, p.name, p.company_id AS partner_company, u.company_id AS user_company
FROM res_partner p JOIN res_users u ON (u.partner_id = p.id)
WHERE p.company_id IS NOT NULL AND p.company_id != u.company_id;
-- To fix the partners
UPDATE res_partner p SET company_id = u.company_id
FROM res_users u
WHERE u.partner_id = p.id AND p.company_id IS NOT NULL;
Technically id.company_ id: # if partner is global we keep it that way
user.partner_ id.write( {'company_ id': user.company_ id.id})
-----------
- l.11-13, 25-28: simplify code: using a browse record you can make the code much simpler, and there is really no need to call _get_company:
user = self.browse(cr, uid, user_id, context=context)
if user.partner_
Thanks!