~sebastien.beau/magentoerpconnect/oerp6.1-cleanning

« back to all changes in this revision

Viewing changes to magentoerpconnect/partner.py

  • Committer: Sébastien Beau
  • Date: 2012-12-07 13:18:05 UTC
  • mfrom: (676.2.39 magentoerpconnect)
  • Revision ID: sebastien.beau@akretion.com-20121207131805-o4tgotytj3ku580m
[MERGE] merge with cleaning branch, please do not forget to update dependency, product-extra-addons, openobject-extention, e-commerce-adddons. 

magentoerpconnect :
- REFACTOR
    - refactor the invoice syncronisation 
        2 modules are available, 1 for using Magento Invoice, one for using OpenERP invoice
        moreover if invoice syncronisation failed try to map if an existing one already exist : fonction => map_magento_order 
    - refactor view for compatibility in multi-e-commerce solution
    - NAME REFACTOR : by default use only name if you need to use the lastname and firstname please first update magentoerpconnect and them install magentoerpconnect_partner_surname. DO IT ON A DATABASE TEST BEFORE. If you have any trouble please open a bug on lp
    - use new api for moving the category and updating the stock information

    ADD
        - add reporting when exporting stock level

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
23
23
#########################################################################
24
24
 
25
 
from osv import osv, fields
26
 
from tools.translate import _
27
 
import magerp_osv
 
25
import hashlib
 
26
 
 
27
from openerp.osv import fields
 
28
from .magerp_osv import MagerpModel
28
29
from base_external_referentials.decorator import only_for_referential
29
 
import hashlib
30
30
 
31
 
class res_partner_category(magerp_osv.magerp_osv):
 
31
class res_partner_category(MagerpModel):
32
32
    _inherit = "res.partner.category"
33
 
 
34
 
    _columns = {
35
 
                    'tax_class_id':fields.integer('Tax Class ID'),
 
33
    _columns = {'tax_class_id':fields.integer('Tax Class ID'),
36
34
                }
37
 
res_partner_category()
38
35
 
39
 
class res_partner_address(magerp_osv.magerp_osv):
 
36
class res_partner_address(MagerpModel):
40
37
    _inherit = "res.partner.address"
41
38
 
42
 
 
43
 
    #TODO maybe move the fields company, firstname, lastname in an extra module
44
 
    #On v7 the partner address model will totaly change so maybe it's not worth
45
 
    def _get_partner_name(self, cr, uid, ids, field_name, arg, context=None):
46
 
        res ={}
47
 
        for partner in self.browse(cr, uid, ids, context=context):
48
 
            res[partner.id] = ((partner.company and partner.company + ' : ') or '') + \
49
 
                              (partner.lastname and partner.lastname + ' ' or '') + \
50
 
                              (partner.firstname or '')
51
 
        return res
 
39
    #Migration script for 6.1.0 to 6.1.1
 
40
    def _auto_init(self, cr, context=None):
 
41
        # recompute the field name with firstname + lastname
 
42
        # in order to have the same data as the data of base_partner_surname
 
43
        first_install=False
 
44
        cr.execute("SELECT column_name FROM information_schema.columns "
 
45
                   "WHERE table_name = 'res_partner_address' "
 
46
                   "AND column_name = 'firstname'")
 
47
        if cr.fetchone():
 
48
            cr.execute(
 
49
                "UPDATE res_partner_address "
 
50
                "SET name = CASE "
 
51
                  "WHEN firstname IS NOT NULL AND lastname IS NOT NULL THEN (firstname || ' ' || lastname) "
 
52
                  "WHEN firstname IS NOT NULL AND lastname IS NULL THEN firstname "
 
53
                  "WHEN firstname IS NULL AND lastname IS NOT NULL THEN lastname "
 
54
                  "ELSE name "
 
55
                "END"
 
56
                  )
 
57
            cr.execute("ALTER TABLE res_partner_address "
 
58
                       "RENAME COLUMN firstname TO first_name")
 
59
            cr.execute("ALTER TABLE res_partner_address "
 
60
                       "RENAME COLUMN lastname TO last_name")
 
61
        return super(res_partner_address, self)._auto_init(cr, context=context)
52
62
 
53
63
    _columns = {
54
 
        'name': fields.function(_get_partner_name, obj="res.partner.address", type = 'char', size = 256, string='Name',
55
 
                store = {
56
 
                    'res.partner.address' : (lambda self, cr, uid, ids, c={}: ids,
57
 
                                                    ['company', 'firstname', 'lastname'], 10)}),
58
64
        'company':fields.char('Company', size=100),
59
 
        'firstname':fields.char('First Name', size=100),
60
 
        'lastname':fields.char('Last Name', size=100),
61
65
        'is_magento_order_address':fields.boolean('Magento Order Address?'), #TODO still needed?
62
 
                }
 
66
        }
63
67
    _defaults = {
64
68
        'is_magento_order_address': lambda * a:False,
65
 
                 }
 
69
        }
66
70
 
67
71
    @only_for_referential('magento')
68
72
    def ext_create(self, cr, uid, external_session, resources, mapping, mapping_id, context=None):
74
78
            ext_create_ids[resource_id] = ext_id
75
79
        return ext_create_ids
76
80
 
77
 
res_partner_address()
78
 
 
79
 
class res_partner(magerp_osv.magerp_osv):
 
81
class res_partner(MagerpModel):
80
82
    _inherit = "res.partner"
81
83
 
82
84
    def _is_magento_exported(self, cr, uid, ids, field_name, arg, context=None):
94
96
        return res
95
97
 
96
98
    _columns = {
97
 
                    'group_id':fields.many2one('res.partner.category', 'Magento Group(Category)'),
98
 
                    'store_id':fields.many2one('magerp.storeviews', 'Last Store View', help="Last store view where the customer has bought."),
99
 
                    'store_ids':fields.many2many('magerp.storeviews', 'magerp_storeid_rel', 'partner_id', 'store_id', 'Store Views'),
100
 
                    'website_id':fields.many2one('external.shop.group', 'Magento Website', help='Select a website for which the Magento customer will be bound.'),
101
 
                    'created_in':fields.char('Created in', size=100),
102
 
                    'created_at':fields.datetime('Created Date'),
103
 
                    'updated_at':fields.datetime('Updated At'),
104
 
                    'emailid':fields.char('Email Address', size=100, help="Magento uses this email ID to match the customer. If filled, if a Magento customer is imported from the selected website with the exact same email, he will be bound with this partner and this latter will be updated with Magento's values."),
105
 
                    'mag_vat':fields.char('Magento VAT', size=50, help="To be able to receive customer VAT number you must set it in Magento Admin Panel, menu System / Configuration / Client Configuration / Name and Address Options."),
106
 
                    'mag_birthday':fields.date('Birthday', help="To be able to receive customer birthday you must set it in Magento Admin Panel, menu System / Configuration / Client Configuration / Name and Address Options."),
107
 
                    'mag_newsletter':fields.boolean('Newsletter'),
108
 
                    'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"),
109
 
                    'magento_pwd': fields.char('Magento Password', size=256),
110
 
                }
 
99
        'group_id':fields.many2one('res.partner.category', 'Magento Group(Category)'),
 
100
        'store_id':fields.many2one('magerp.storeviews', 'Last Store View', help="Last store view where the customer has bought."),
 
101
        'store_ids':fields.many2many('magerp.storeviews', 'magerp_storeid_rel', 'partner_id', 'store_id', 'Store Views'),
 
102
        'website_id':fields.many2one('external.shop.group', 'Magento Website', help='Select a website for which the Magento customer will be bound.'),
 
103
        'created_in':fields.char('Created in', size=100),
 
104
        'created_at':fields.datetime('Created Date'),
 
105
        'updated_at':fields.datetime('Updated At'),
 
106
        'emailid':fields.char('Email Address', size=100, help="Magento uses this email ID to match the customer. If filled, if a Magento customer is imported from the selected website with the exact same email, he will be bound with this partner and this latter will be updated with Magento's values."),
 
107
        'mag_vat':fields.char('Magento VAT', size=50, help="To be able to receive customer VAT number you must set it in Magento Admin Panel, menu System / Configuration / Client Configuration / Name and Address Options."),
 
108
        'mag_birthday':fields.date('Birthday', help="To be able to receive customer birthday you must set it in Magento Admin Panel, menu System / Configuration / Client Configuration / Name and Address Options."),
 
109
        'mag_newsletter':fields.boolean('Newsletter'),
 
110
        'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"),
 
111
        'magento_pwd': fields.char('Magento Password', size=256),
 
112
        }
111
113
 
112
114
    _sql_constraints = [('emailid_uniq', 'unique(emailid, website_id)', 'A partner already exists with this email address on the selected website.')]
113
115
 
124
126
            AND ir_model_data.model = 'res.partner'
125
127
            AND ir_model_data.referential_id = %(ref_id)s
126
128
        WHERE ir_model_data.res_id IS NULL AND magerp_storeid_rel.store_id IN %(store_ids)s"""
127
 
        params = {'ref_id': external_session.referential_id.id, 
 
129
        params = {'ref_id': external_session.referential_id.id,
128
130
                  'store_ids': tuple(store_ids)}
129
131
        cr.execute(query,params)
130
132
        results = cr.dictfetchall()
134
136
    @only_for_referential('magento')
135
137
    def _transform_and_send_one_resource(self, cr, uid, external_session, resource, resource_id,
136
138
                            update_date, mapping, mapping_id, defaults=None, context=None):
137
 
        res = super(res_partner, self)._transform_and_send_one_resource(cr, uid, external_session, 
 
139
        res = super(res_partner, self)._transform_and_send_one_resource(cr, uid, external_session,
138
140
            resource, resource_id, update_date, mapping, mapping_id, defaults=defaults, context=context)
139
141
        if res:
140
142
            address_obj = self.pool.get('res.partner.address')
142
144
            for resource_id in resource_ids:
143
145
                result = address_obj._export_one_resource(cr, uid, external_session, resource_id, context=context)
144
146
        return res
145
 
 
146
 
res_partner()