Commit Graph

36 Commits

Author SHA1 Message Date
Jairo Llopis
1531b29de4 [FIX] contract: do not die if modified partner has contracts in several companies
In a multicompany scenario where a contact belongs to a company and has contracts in several companies, if the user goes to the contact to edit anything, when saving, it will trigger the recomputation of the `commercial_partner_id` field, which gets populated to all the related contracts, and will undeniably fail with an `AccessError`.

A simple test is provided that, without the fix, fails like this:

```
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: ERROR: test_multicompany_partner_edited (odoo.addons.contract.tests.test_contract.TestContract)
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: ` Editing a partner with contracts in several companies works.
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: Traceback (most recent call last):
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/auto/addons/contract/tests/test_contract.py", line 2513, in test_multicompany_partner_edited
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: `     'parent_id': parent_partner.id,
2020-06-25 07:21:24,859 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/auto/addons/partner_autocomplete/models/res_partner.py", line 183, in write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     res = super(ResPartner, self).write(values)
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/res_partner.py", line 570, in write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     result = result and super(Partner, self).write(vals)
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/auto/addons/mail/models/mail_thread.py", line 321, in write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     result = super(MailThread, self).write(values)
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/auto/addons/mail/models/mail_activity.py", line 613, in write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     return super(MailActivityMixin, self).write(vals)
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3381, in write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     self.recompute()
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/custom/src/odoo/odoo/models.py", line 5308, in recompute
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     target._write(dict(vals))
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3433, in _write
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     self.check_access_rule('write')
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `   File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3081, in check_access_rule
2020-06-25 07:21:24,860 33 ERROR devel odoo.addons.contract.tests.test_contract: `     + ' - ({} {}, {} {})'.format(_('Records:'), invalid.ids[:6], _('User:'), self._uid)
2020-06-25 07:21:24,861 33 ERROR devel odoo.addons.contract.tests.test_contract: ` odoo.exceptions.AccessError: ('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: Contract, Operation: write) - (Records: [101], User: 12)', None)
```

@Tecnativa TT24482
2024-03-23 15:10:10 +00:00
sbejaoui
5635f524f1 [IMP] - Contract: add new recurring_rule_type quarterly and semesterly 2024-03-23 15:10:10 +00:00
Pedro M. Baeza
6b0f5086b6 [FIX+IMP] contract: improve test coverage with new sections + fix search method 2024-03-23 15:10:10 +00:00
sbejaoui
6cb0fc6ebe [IMP] contract: Improve partner With running contracts search view filter + contract termination 2024-03-23 15:10:09 +00:00
sbejaoui
8412378133 [12.0][IMP] - Add an action for contracts manual invoicing
It happen that a company has to trigger the invoicing action to generate invoices before
the scheduled date (to print and prepare invoices documents, check invoices, etc.).
This requires technical access for end users with the risk that this represents.

This commit adds a new wizard to run the invoicing action for a given date with a helper
to see and check the contract that will be invoiced. When the manual action is called,
the system displays all created invoices.

[12.0][IMP] - log the manual invoice action in contract chatter

[IMP] - Add alink to the invoice in contract message at manual invoicing

[IMP] - Improve code

[FIX] - log message for invoice creation only when there is an invoice

[IMP] - split the manual invoice menu into to menus sale & purhcase

[IMP] - hide invoice button if there is nothing to invoice
2024-03-23 15:10:09 +00:00
sbejaoui
d1e7dde56e [IMP+FIX] contract: Add failing test for wrong invoicing date after contract line stop + stop update recurring_next_date 2024-03-23 15:10:09 +00:00
sbejaoui
90fa0e055f [IMP+FIX] contract: Several things
- Add failing test for next invoice date before the last date invoiced
- raise an error when next invoice date before the last date invoiced
- Add note field to contract
- add new option: create_new_line_at_contract_line_renew
  Add a company config option to decide whether to create or to extend contract
  line at renew action
- extend contract line at renewal
- improve code: unify methods argument _renew_create_line and _renew_extend_line
2024-03-23 15:10:09 +00:00
sbejaoui
13c5f8ecfd [FIX+REF] contract: Improve unit tests + add unit test for different combinations for next invoicing period + simplify _get_period_to_invoice 2024-03-23 15:10:09 +00:00
Stéphane Bidoul (ACSONE)
68d2b84a4b [REF+FIX+IMP] contract: Several refactorings + fixes + imps
- REF: Refactor _update_recurring_next_date
  Reuse the logic that is now fully located in _get_recurring_next_date.
- REF: re-add _compute_first_recurring_next_date
  for backward compatibility
- FIX: add missing dependency in computed field
- REF: remove one monthlylastday special case
  get_relative_delta now works the same for all recurring rules.
  Move the special case handling to _init_last_date_invoiced
  which is used only for migration.
- IMP: support pre-paid for monthlylastday
  monthlylastday is (almost) not a special case anymore \o/.
  montlylastday is simply a montly period where the
  periods are aligned on month boundaries.
  The last bit of special casing is that postpaid generates
  invoice the day after the last dasy of the period, except
  for monthlylastday where the invoice is generated on the
  last day of the period. This last exception will disappear
  when we put the offset under user control.
  This is a breaking change because the post-paid/pre-paid
  mode becomes relevant for monthlylastday invoicing.
  The field becomes visible in the UI. Code that generate
  monthlylastday contract lines must now correctly set
  the pre-paid/post-paid mode too. Some tests have had
  to be adapted to reflect that.
- REF: make recurring_invoicing_offset a computed field
  In preparation to making it user modifiable.
- REF: make get_next_period_date_end public
  Make it public because it is the core logic of the module.
  Also, clarify that recurring_invoicing_type
  and recurring_invoicing_offset are needed only when
  we want the next period to be computed from a
  user chosen next invoice date.
- REF: rename _get_recurring_next_date as get_next_invoice_date
  It is easier to understand. Also make it public.
2024-03-23 15:10:09 +00:00
Stéphane Bidoul (ACSONE)
ba712d2a1a [REF] contract: Several refactorings
- rename misnamed methods
- clarify _get_recurring_next_date
  First compute the next period end date,
  then derive the next invoice date from the next
  period stard and end date.
- handle max_date_end in _get_recurring_next_date
  This concentrates all next date calculation
  logic in one place, and will allow further simplifications.
- add next period start/end fields
  Add two computed field showing the next period
  start and end date. This improve the UX and will
  enable further simplifications in the code.
- refactor _get_period_to_invoice
  Move the part of the logic that compute the next
  period depending on the chosen next invoice date
  to _get_next_period_date_end.
2024-03-23 15:10:09 +00:00
Pedro M. Baeza
912480c68d [FIX] contract: Don't execute onchange after invoice creation + Tests with duplicated name
- Don't execute onchange after invoice creation
  Using that approach (that is the current one in core)  has a lot of side effects and
  performance bottlenecks. You can read odoo/odoo#40156 for summarizing them.
  This also improves the handling of the values of payment term an fiscal position
  for using the partner ones if not set.
- Tests with duplicated name
  So they are not executed at all. Detected by chance looking for a test for the other PR.
2024-03-23 15:10:09 +00:00
Sergio Teruel
5d83f9de6d [IMP] contract: Fix test crash with other modules 2024-03-23 15:10:09 +00:00
Thomas Binsfeld
489a79588d [REF] contract: Several things
[REF] use context_today instead of time in filters
[REF] Contract: split from analytic account
[REF] Contract Sale Invoicing: split from analytic account
[REF] Contract Sale Invoicing: update translations
[IMP] - Assert that the predecessor is available for new link at uncancel
[RMV] - remove usless changes
[RMV] - Remove usless field recurring_invoices
  after the total isolation between contract model and account analytic one.
  recurring_invoices which was used to mark analytic account as contract became usless
[IMP] - P3 syntax
[IMP] - use @openupgrade.migrate() and openupgrade.logged_query
[IMP] - drop transient table in migration script
2024-03-23 15:10:09 +00:00
sbejaoui
05630c38e5 [REF+FIX+IMP] contract: Several things
[FIX] - manual_renew_needed should be visible to all contract users
[REF] - add _get_next_invoiced_period method
[FIX] - Fix In progress contract filter
[REF] - add method to get quantity to invoice
  the contract line quantity can be in some use cases variable, to simplify
  the way it is changed we add a new method _get_quantity_to_invoice.
[FIX] - Onchange contract line don't reste contract lines
[FIX] - Rename _get_invoiced_period to _get_period_to_invoice
[ADD] - Add stop_at_date_end to _get_period_to_invoice
[FIX] - Remove useless filter
[FIX] - don't play onchange date_start for old lines on contract template change
[FIX] - Fix stop post message
[FIX] - Fix sale_contract_count should count all partner contract
[FIX] - set recurring_next_date to False if contract line stoped at last date invoiced
[FIX] - Group by next_invoice also considers dates in the past
[IMP] - A canceled contract line can't be set to auto-renew
[REF] Contract: pep8
[IMP] Contract: update USAGE section of README
[IMP]call onchange_is_auto_renew when changing template
2024-03-23 15:10:09 +00:00
Thomas Binsfeld
b5590b6b9a [FIX] Contract to Invoice: take contract vendor instead of partner's 2024-03-23 15:10:09 +00:00
sbejaoui
19f9587025 [ADD] - Add more value for auto_renew_rule_type
[REF] - refactoring for compute_first_date_end

[RMV] - remove auto_renew_rule_type option monthlylastday

[IMP] - rename manual_renew_needed label

[IMP] - use get_product_multiline_description_sale to get contract line description
2024-03-23 15:10:09 +00:00
sbejaoui
9fbf38a74a [IMP] - Should be able to stop a past contract line 2024-03-23 15:10:09 +00:00
sbejaoui
1881028b32 [FIX+IMP] contract: several things
[FIX] - as date_start is required, constraints on it become useless
[FIX] - for finished contract _get_lines_to_invoice should return False
[FIX] - default value for active field in contract line
[FIX] - fix flake8
[IMP] - check invoice line vals before assignment
[FIX] - Fix unit tests.
[FIX] - do not copy last_date_invoiced on plan_successor
[FIX] - renew only recurring_invoices contract
[FIX] - filter by termination_notice for contract line to renew
[IMP] - Improve inprogress search filter
[IMP] - Link invoice line to contract lines
[IMP] - Add index on contract line
[IMP] - Add is_suspended flag and _search_state
[IMP] - Add is_suspended flag to stop contract line
[MV] - move onchange method to contract_product module
[IMP] - Replace is_suspended flag by manual_renew_needed
  Add a computed field for the first date of the termination notice period
  Adapt state compute and search method
[IMP] - Improve unit tests
2024-03-23 15:10:09 +00:00
Thomas Binsfeld
f48610f7e1 [REF+FIX+IMP] Contract: invoice creation + date start required for contract line + Gitignore: .eggs + tests: base the cron check on invoice lines instead of invoices + payment term 2024-03-23 15:10:09 +00:00
sbejaoui
103d5c1c66 [IMP] contract: Make recurrence mechanism on contract line
Make recurrence mechanism on contract line and some other refactoring

[FIX] - Keep contract_cron on account_analytic_account model

contract_cron defined with no_update option.
Changing it, will cause issue to past version installation.

[IMP] - Fix recurring_next_date default value

recurring_next_date should have start_date as default value in prepaid policy
and start_date + invoicing_interval if postpaid

[FIX] - Fix test check no journal

[IMP] - Return created invoices on recurring_create_invoice

[IMP] - Specific process to compute recurring_next_date for  monthly-last-day

fixes: #198

[ADD] - Add Post-migration script to bring recurrence info from contract to contract lines

[ADD] - Add search filter based on date_end and recurring_next_date

 - not_finished filter in contract search view
 - finished filter in contract search view
 - Next Invoice group by in contract search view

[ADD] - Add unit tests

- cases to compute first recurring next date
- contract recurring_next_date
- contract date_end

[IMP] - Improve Unit tests

[12.0][IMP] - Add strat/stop wizard to contract line

[12.0][IMP] - Add pause button to contract line

[IMP] - Add state filed in contract line form

[FIX] - stop don't change date_end for finished contract line

[IMP] - Change contract line buttons visibility

Add renewal process with termination notice

[FIX] - don't consider stop_date If it is after the contract line end_date

[IMP] - consider more cases in stop_plan_successor

[IMP] - cancel upcoming line on stop

[IMP] - Chnage next invoice date on un-cancel

[IMP] - Post message in contract on contract line actions

[IMP] - check contract line overlap

[FIX] - invoice last period for post-paid case

[IMP] - Add primary views for contract

[IMP] - don't use related filed for partner_id and pricelist_id

[FIX] - fix stop_plan_successor case 5

contract line start in the suspension period and end after it

[IMP] - improve cancel/uncancel process

[FIX] - Test if start_date is set before compute

[FIX] - date_end include in the period in auto_renew case

[FIX] - in suspension case, contract line should start a day after the end

[IMP] - confirm message on contract line cancel

[IMP] - hide recurring_invoicing_type if recurring_rule_type is monthlylastday

for the monthlylastday case, pre-paid is logicly impossible,
if monthlylastday is set, we consider only post-paid case

[IMP] - Improve unit tests

[IMP] - store last_date_invoiced on contract_line

Improve CRITERIA_ALLOWED_DICT

[IMP] - code improvement

[IMP] - Use last_date_invoiced to set marker in invoice description

[IMP] - add migration script to init last_day_invoiced and some other improvement

[FIX] - a contract line suspended should start a day after the suspension end

[IMP] - don't allow to unlink uncnaceled contrac line

[FIX] - check date_start before onchange

[FIX] - compute recurring_next_date for contract

[IMP] - get contract line default data onchange product_id

[IMP] - Add responsible to contract form view

[FIX] - contract recurring_next_date ignore canceled lines

[FIX] - fix _get_invoiced_period if recurring_next_date manually updated

[IMP] - archive contract_line on contract archive
2024-03-23 15:10:09 +00:00
sbejaoui
aa75041890 [MIG] contract: Migration to 12.0 2024-03-23 15:10:09 +00:00
Pedro M. Baeza
86c5726815 [IMP] contract: Don't depend on external data
The test as it was, leaves to the demo pricelist the control on the price of
the product, so other modules that modifies this pricelist will make the
test to fail.

This is the minimum change needed for avoiding the problem.
2024-03-23 15:10:09 +00:00
mreficent
5ca6bc6936 [IMP] Make sure it works for sale and purchase contracts
[UPD] Update contract.pot
2024-03-23 15:10:09 +00:00
Stefan Becker
d382861c97 [IMP] Add type to analytic account / contract 2024-03-23 15:10:08 +00:00
Carlos Dauden
d7e008ed06 [IMP] contract: Add extend existing invoice possibility 2024-03-23 15:10:08 +00:00
Pedro M. Baeza
52e822f80a [IMP] contract: Automatic prices for lines 2024-03-23 15:10:08 +00:00
Pedro M. Baeza
60f69376be [10.0][FIX+IMP] contract: Improve usability and don't fail on wrong data (#130)
* [FIX+IMP] contract: Improve usability and don't fail on wrong data

* Cron create invoices masked for avoiding silent errors
* New constraints for assuring data consistency
* UI helps for entering consistent data
* Spanish translation
* Remove double company_id field on form
2024-03-23 15:10:08 +00:00
Fekete Mihai
523cb479d0 [MIG] contract: Migration to version 11.0 2024-03-23 15:10:08 +00:00
Carlos Dauden
f789fbac86 [IMP] contract: Module contract improvements (#107) 2024-03-23 15:10:08 +00:00
Pedro M. Baeza
6895fc2d29 [FIX] contract: fix views assignment + improvement on tests + copyright in headers
**Be totally deterministic about which views to use**

Having a primary view that is not explicitly declared to be uses and w/o priority
makes Odoo to choose between one of them randomly (well, not exactly, but kind of),
so we put here which views to use.

I have also put tree view as primary and put a large priority for not being
selected on other actions that don't have this explicit views.

A friendly name in views is also assigned.

**Improvements in tests**

* Use SavepointCase for making the setup only once for all tests
* Make them inheritable, creating a base class with only the setup,
  so that it can be inherited without the need of executing all tests
  contained here each time you inherit it, and adding other class
  in the same module that inherits from the base class that actually
  performs the tests.
* Removed duplicated test method
2024-03-23 15:10:08 +00:00
Dave Lasley
d8ced6beda [FIX] contract: Template lines handling (#92)
Update contract template lines handling to fix #80, and fix #59 #100
2024-03-23 15:10:08 +00:00
cubells
8dce5c58af [IMP][10.0] contract: Add report + send by mail (#86)
* [IMP][9.0] contract: Add report + send by mail

* Update translation and rename contract report

* Changes requested and translation updated
2024-03-23 15:10:08 +00:00
Dave Lasley
5b30e3b6f9 [IMP][10.0] contract: Add templating (#42)
Add template functionality for contracts
2024-03-23 15:10:08 +00:00
Pedro M. Baeza
589e1dcd22 [MIG] contract: Migration to version 10.0 2024-03-23 15:10:08 +00:00
Carlos Dauden
7cb0967f4b [IMP] contract: Add past receipt type. Fix yearly. Add month last day 2024-03-23 15:10:08 +00:00
Carlos Incaser
7b90151efd [MIG] contract: from v7 to v9 improving features
* Tests added
* Filters added.
* Add _id/_ids in old property fields
* Translations
2024-03-23 15:10:08 +00:00