Skip to content
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

New API in connector, bump to 3.0.0 #47

Merged
merged 51 commits into from
Apr 1, 2015

Conversation

guewen
Copy link
Member

@guewen guewen commented Feb 19, 2015

The changes done here will break the API compatibility.
However, they are necessary to keep up with the changes in Odoo.

The API in the connector still uses the cr, uid, ids, context api, even if
hidden in connector.Session. Not using new recordsets is restricting.

Example:
If I implements a new onchange on sale.order:

class SaleOrder(models.Model):
    @api.onchange('workflow_process_id'):
    def onchange_workflow_process_id(self):
        self.payment_method_id = self.workflow_process_id.payment_method_id

Then I won't be able to call from within a ConnectorUnit directly.
Locally I could do:

import openerp
[...]

  env = openerp.api.Environment(self.session.cr,
                                self.session.uid,
                                self.session.context)
  sale = env['sale.order'].new(values)
  sale.onchange_workflow_process_id()

But it would be far better to include the new API in the root classes.

Changes:

  • Add openerp.api.Environment in Session
    It is accessible in self.env in Session and all
    ConnectorUnit instances.
    Also in ConnectorUnit, model returns the current (new api!) model:

        # On the current model
        self.model.search([])
        self.model.browse(ids)
        # on another model
        self.env['res.users'].search([])
        self.env['res.users'].browse(ids)
  • Deprecate the CRUD methods in Session

        # NO
        self.session.search('res.partner', [])
        self.session.browse('res.partner', ids)
    
        # YES
        self.env['res.partner'].search([])
        self.env['res.partner'].browse(ids)
  • Environment.set_lang() is removed. It was modifying the context
    in place which is not possible with the new frozendict context. It
    should be done with:

        with self.session.change_context(lang=lang_code):
            ...
  • Add an argument on the Binders methods to return a browse record

        binder.to_openerp(magento_id, browse=True)
  • Shorten ConnectorUnit.get_binder_for_model to
    ConnectorUnit.binder_for

  • Shorten ConnectorUnit.get_connector_unit_for_model to
    ConnectorUnit.unit_for

  • Renamed Environment to ConnectorEnvironment to avoid
    confusion with openerp.api.Environment

  • Renamed the class attribute ConnectorUnit.model_name to
    ConnectorUnit.for_model_name.

  • Added _base_binder, _base_mapper, _base_backend_adapter in
    the synchronizers (Importer, Exporter) so it is no longer required to
    override the binder, mapper, backend_adapter property
    methods

  • Session.change_context() now supports the same
    argument/keyword arguments semantics than
    openerp.model.BaseModel.with_context().

  • Renamed ExportSynchronizer to Exporter

  • Renamed ImportSynchronizer to Importer

  • Renamed DeleteSynchronizer to Deleter

  • Session.commit do not commit when tests are running

  • Cleaned the methods that have been deprecated in version 2.x

""" Context Manager: temporarily change the user's session and
restablish the normal user at closing,
"""
raise Exception('Deprecated: use sudo() on a recordset.')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just yield a new Environment, and restore the original at closing.

guewen added a commit to guewen/connector-ecommerce that referenced this pull request Feb 19, 2015
This is required by the new api.onchange methods.
The change needs OCA/connector#47
'new-api model/recordset.')
return self.session.pool.get(self.environment.model_name)

def recordset(self, model=None):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The perfect name for this method would have been model... but it is already used.
recordset is a bit odd as it returns a model (but a model is also a new recordset in the new api), but I can't find a better name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about records?

users = self.records().search([])  # when the model of the ConnectorUnit is 'res.users'
users = self.records('res.users').search([])  # when the model is another thing
things = self.records().browse(ids)
things.unlink()

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.22%) to 71.14% when pulling 0694a72440ca1ee07becabcef17dd5914d8480bd on guewen:8.0-connector-new-api into c89b66e on OCA:8.0.

Start to deprecate the Session class which can be entirely replaced by
openerp.Environment and recordsets. The first step is to include the env in
Session, and in a later version we'll replace it entirely by
openerp.Environment.

Now, 'self.env' in any ConnectorUnit returns the new API 'env'.
Beware, it should now be used as a contextmanager
Allow to customize them without overriding the whole property mapper or
backend_adapter.
Do not point directly to them from ConnectorUnit or Environment or it would
not return the correct ones inside a Session.change_context() or Session.change_user()
And corrected a wrong __str__!
@coveralls
Copy link

Coverage Status

Coverage increased (+3.88%) to 75.24% when pulling 3dfb312 on guewen:8.0-connector-new-api into 8a23ebe on OCA:8.0.

When a job has been canceled, it could no longer be read
Also documented a bit the construction of mappings in the metaclass
@guewen guewen changed the title [WIP] New API in connector New API in connector Mar 20, 2015
@guewen guewen changed the title New API in connector New API in connector, bump to 3.0.0 Mar 20, 2015
@guewen
Copy link
Member Author

guewen commented Mar 20, 2015

Branch's ready, I need reviews

guewen added a commit to guewen/connector-ecommerce that referenced this pull request Mar 20, 2015
This is required by the new api.onchange methods.
The change needs OCA/connector#47
guewen added a commit to guewen/connector-ecommerce that referenced this pull request Mar 20, 2015
This is required by the new api.onchange methods.
The change needs OCA/connector#47
@lmignon
Copy link
Contributor

lmignon commented Mar 20, 2015

@thank you @guewen for this hard work... Even if there are a lot of changes, I did not find any comments to make. 👍 (Code review)

@pedrobaeza
Copy link
Member

Well, I have to check it when I change Prestashop connector, but at first glance, it seems 👍

I think we can merge and then make possibles PRs to fix problems.

@tremlin
Copy link

tremlin commented Apr 1, 2015

I reviewed the code and tested it (as part of magentoerpconnect), I recommend it for merging 👍
Thanks for the port to v8!

@pedrobaeza
Copy link
Member

I proceed with the merge then and possible fixes will come as another PRs.

Thanks to all that have contributed!

pedrobaeza added a commit that referenced this pull request Apr 1, 2015
New API in connector, bump to 3.0.0
@pedrobaeza pedrobaeza merged commit ca5916d into OCA:8.0 Apr 1, 2015
@pedrobaeza
Copy link
Member

@guewen, can you please include the same version log of this PR in any side of the web to have it as reference?

@@ -1,6 +1,74 @@
Changelog
---------

3.0.0 (not released)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date needs to be set

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can make it via direct commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@guewen
Copy link
Member Author

guewen commented Apr 2, 2015

@guewen, can you please include the same version log of this PR in any side of the web to have it as reference?

What do you mean exactly by "in any side of the web"?
I updated http://odoo-connector.com if that's what you mean.

@pedrobaeza
Copy link
Member

Yeah, http://odoo-connector.com/project/changes.html#id2 is what I mean. Thanks.

yucer pushed a commit to elego/connector-redmine that referenced this pull request Mar 17, 2017
yucer pushed a commit to elego/connector-redmine that referenced this pull request Mar 22, 2017
eLBati pushed a commit to eLBati/connector-redmine that referenced this pull request Apr 23, 2018
[MIG] Rename manifest file

[MIG] Replace "openerp" ocurrences with "odoo"

[MIG] Do not use RedmineConnectorSession anymore

(issue #212)

- extend ConnectorEnvironment to host the redmine_cache that was
  previously extended in RedmineConnectorSession

- remove session parameter from connector.get_environment (the
  connector module takes the environment from the backend object
  now). the default language from the backend is not applied there,
  because the session object is not available anymore.

- Simplify RedmineModelBinder reusing the generalizations from of
  Binder. This way the use of the session property is not needed.

- Proxy the redmine_cache of RedmineImportSyncronizer to the one saved
  in the connector environment. The same happens for RedmineAdapter

- Simplify RedmineImportSynchronizer to avoid the use of session

- remove "session" parameter from: import_batch, import_record,
  mock_delay, get_environment, import_single_user_time_entries. It is
  not replaced with "env", because env parameter passing is also
  removed in the last version of odoo_connector. the environment is
  now taken from the backend_record...

- that's why some methods pass now the backend object instead of the
  backend_id. The backend is used now to get the environment, not at
  the opossite.

[MIG] replace `hr.analytic.timesheet` by `account.analytic.line`

- since v9 the model 'hr.analytic.timesheet` has been replaced by
  `account.analytic.line`:

  https://github.com/OCA/OpenUpgrade/blob/9.0/addons/hr_timesheet/migrations/9.0.1.0/post-migration.py#L17

- note that in v9 we need also a mapper, in order to set::

       is_timesheet = True

  during the import of the timesheet records

[MIG] Use queue_job module from OCA/queue

see: OCA/queue#1

[MIG] Renamed ImportSynchronizer to Importer

- see: OCA/connector#47

[MIG] import exception module

- the job exception types has been moved to the module: `queue_job`.

- They are still loaded / proxied by the module
  `connector.exception`.

- But somehow this requires that the module is correctly imported.

- It is better to use always import. See:
  http://effbot.org/zone/import-confusion.htm

- Import made similar to:

  OCA/connector#188 (comment)

[MIG] slight changes to the Binder

- Rename 'to_backend' to 'to_external'

- Rename 'to_odoo' to 'to_internal'

see: OCA/connector@fef7ee2

pep8 adjustments

[MIG] rename ImportSynchronizers that left

[MIG] fix hr_timesheet_sheet_form

- the `buttons` element taked as reference by the previous version
  does not exist anymore

- another position was selected so the result is the same

fix pylint suggestions

fix pyflakes errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants