22
22
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
23
23
#########################################################################
25
from osv import osv, fields
26
from tools.translate import _
27
from openerp.osv import fields
28
from .magerp_osv import MagerpModel
28
29
from base_external_referentials.decorator import only_for_referential
31
class res_partner_category(magerp_osv.magerp_osv):
31
class res_partner_category(MagerpModel):
32
32
_inherit = "res.partner.category"
35
'tax_class_id':fields.integer('Tax Class ID'),
33
_columns = {'tax_class_id':fields.integer('Tax Class ID'),
37
res_partner_category()
39
class res_partner_address(magerp_osv.magerp_osv):
36
class res_partner_address(MagerpModel):
40
37
_inherit = "res.partner.address"
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):
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 '')
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
44
cr.execute("SELECT column_name FROM information_schema.columns "
45
"WHERE table_name = 'res_partner_address' "
46
"AND column_name = 'firstname'")
49
"UPDATE res_partner_address "
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 "
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)
54
'name': fields.function(_get_partner_name, obj="res.partner.address", type = 'char', size = 256, string='Name',
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?
64
68
'is_magento_order_address': lambda * a:False,
67
71
@only_for_referential('magento')
68
72
def ext_create(self, cr, uid, external_session, resources, mapping, mapping_id, context=None):
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),
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
114
_sql_constraints = [('emailid_uniq', 'unique(emailid, website_id)', 'A partner already exists with this email address on the selected website.')]
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)
140
142
address_obj = self.pool.get('res.partner.address')