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

[RFC] partner_identification: Pass-Through Fields #365

Closed
lasley opened this issue Jan 4, 2017 · 1 comment
Closed

[RFC] partner_identification: Pass-Through Fields #365

lasley opened this issue Jan 4, 2017 · 1 comment

Comments

@lasley
Copy link
Contributor

lasley commented Jan 4, 2017

We're running into some issues with splitting up the partner_identification attributes in medical.

I am in the process of implementing the below code to circumvent the issue in the base medical entity, but am wondering if there is use case outside of medical. Any thoughts?

@api.model
def _compute_identification(self, field_name, category_code, many=False):
    """ It computes a field that indicates a certain ID type.

    Use this on a field that represents a certain ID type. It will compute
    the desired field as that ID(s).

    Set many to ``True`` to allow many results. This can only be used on
    m2m fields.

    Example:

        .. code-block:: python

        social_security_id = fields.Many2one(
            string='Social Security',
            comodel_name='res.partner.id_number',
            compute=lambda s: s._compute_identification(
                'social_security_id', 'SSN',
            )
        )
        npi_ids = fields.Many2many(
            string='NPI Numbers',
            comodel_name='res.partner.id_number',
            compute=lambda s: s._compute_identification(
                'npi_ids', 'NPI', True,
            )
        )

    Args:
        field_name: Name of field to set.
        category_code: Category code of the Identification type.
        many: Allow many results.
    """

    for record in self:
        ids = record.id_numbers.filtered(
            lambda r: r.category_id.code == category_code
        )
        if not ids:
            continue
        value = [(6, 0, ids.ids)] if many else ids[0].id
        setattr(record, field_name, value)

I'll probably also need to make an inverse - at least for the o2o

@lasley lasley changed the title [RFC] partner_contact_identification: Pass-Through Fields [RFC] partner_identification: Pass-Through Fields Jan 4, 2017
@lasley
Copy link
Contributor Author

lasley commented May 17, 2017

tracking in PR #419

@lasley lasley closed this as completed May 17, 2017
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

No branches or pull requests

1 participant