Hi guys,
I've been looking at extending and improving the Odoo webshop. I'm now at the point that I would love to have the ability to let users fill in text fields on a product form (in the webshop). The idea is that they have fields, just like in the back-end that they can fill in.
When the user clicks on Add to Cart the values should be saved and eventually when the user clicks on the pay now button these extra details should be added in the back-end on the sales order / quotation, in these fields that I made: (in the model sale.order.line)
class sample(models.Model): _inherit = 'sale.order.line' height = fields.Integer() width = fields.Integer() numberOfUnits = fields.Integer()
It looks like the @http.route('/shop/payment/validate') in main.py (addons/website_sale/controllers) is responsible for dealing with the data after the user clicks on the Pay Now button. So my questions:
How can I add textfields with labels on the view
How can I send the data to fields that I've custom added in the model sale.order.line?
My initial idea was to add a type under addons/website_sale/models in product.py under the product_attribute class like this:
class product_attribute(osv.Model): _inherit = "product.attribute" _columns = { 'type': fields.selection([('radio', 'Radio'), ('select', 'Select'), ('color', 'Color'), ('hidden', 'Hidden'), ('textfield','Textfield')], string="Type", type="char"), } _defaults = { 'type': lambda *a: 'radio', }
But I have no clue how to further extend this so that a new type is available for product variants.
Any information / help / details are very welcome!
UPDATE:
I have managed to add quite a lot thanks to Jérémy but am now stuck on creating a dropdown on sale.order level. I've inherited the sale.order model and added a Many2one there. This Many2one leads to a new model I've added to save all colours in, so it can be added dynamically.
Code:
class sale_line_colorpicker(models.Model): _name = 'sale.order.colorpicker' _description = dropdown for order/quotation (pick colors)' name = fields.Char('Name', required=True) #Add many2one (for color dropdown) to sale.order class aa_custom_colorpicker_in_salemodel(models.Model): _inherit = 'sale.order' kleurenpicker = fields.Many2one('sale.order.colorpicker','Kleur')
This colorpicker (with all values) should be shown once on the 'Extra' page in the webshop and when the user selects a color it should be added to the order so the automatically generated order in the back-end also has the correct colour filled in. It should be added in this method somehow.. But the colorpicker is on sale.order level and all the rest on sale.order.line level..
class sale_order_line_your_extension(osv.osv): _inherit = "sale.order.line" #Color should still be migrated from quotation/order > invoice! def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None): ret = super(sale_order_line_your_extension, self)._prepare_order_line_invoice_line(cr, uid, line, account_id=False, context=context) hoogte = if line.hoogte: hoogte = line.hoogte ret['hoogte'] = hoogt ret['kleurenpicker'] = kleur return ret
How can I now add a dropdown to the webshop page 'Extra' and how can I get the values from the webshop to my quotation?
Thanks
Yenth
@Yenthe,
Interesting question. I've subscribed to this thread, however if I figure out how to do it myself i'll definitely post back with what I find.
@Luke, I'll soon have to tackle this since I can't delay it much longer so I guess I'll have to dive in to this one myself.. If I find anything / get it working I will let you know too! Any guidance, tips or ideas though? Anything that could point me in the correct way would be nice.
hi yenthe, not sure that variant is the best way... you will generate many new product.product... If i understand your use case, you want just ask more informations on some product... Perso, I will make a new step before shipping, and add for each product/sale_order_line which need more info, a form to complete the missing infos... This page post the form to a new route. (don't forget to break the default link: cart -> checkout ->billing to cart -> extra_info -> checkout -> billing) I don't know your delay, but i'm developping this extra step by default in the next Odoo community version... (which by default allow only x_ fields on sale order)...
@Yenthe,
I'll try and take a look at this on Saturday, however i'm pretty busy at the moment and can't promise i'll be able to.
I'd recommend perhaps digging into the code in website_crm (Odoo core module for contact form), and perhaps the modules related to the new form builder in (master dev branch):
https://github.com/odoo-dev/odoo/tree/master-form-builder-to-merge-mdo
Specifically:
https://github.com/odoo-dev/odoo/tree/master-form-builder-to-merge-mdo/addons/website_form_builder
and:
https://github.com/odoo-dev/odoo/tree/master-form-builder-to-merge-mdo/addons/website_issue
To see if you can make any sense of how it is accomplished there. As from what I understand of your description it is similar in function to what you are trying to accomplish.
I would recommend looking into adding an access rights layer to your module once you figure it out as well, to make sure you've got restrictions on what can and can't be accessed from the frontend as well, just to be safe:
https://github.com/OdooCommunityWidgets/website_multi_image/blob/8.0/website_multi_image/security/ir.model.access.csv
@Yenthe,
I think I read your question incorrectly the first time around. Regarding the two bullet points I'll try to take a look at this on Saturday and see if I can make any progress on it.
@Luke, Thanks for the detailed response & feedback. I've started extending the example of Jérémy and it works pretty good! I'll respond on his answer to so keep an eye out if you want to learn from this too. By the way if you have questions you can contact me too (if I can help you) :) @Jérémy you're right about the product.product and variants being swamped with data, I like your approach more.
@Yenthe,
Thanks, i'd be interested to see what you come up with. Please post back with more info once you've worked out what you want to do, as i'd be very interested to see what you've done.
This could be a very useful feature for textile and print companies with online ordering, as well as a load of other applications.
@Luke, Will do! I'm actually building this for ordering print-related products on this webshop! I'll keep you updated, I might write a blog post about this too :)
@Yenthe,
Brilliant, I look forward to hearing how your project progresses. Most web-to-print type modules i've seen around for Magento and other platforms are ridiculously over-priced, while often offering only basic functionality (eg. custom sizing attributes with calculated fields according to size/finish, and a basic HTML5 editor for basic layouts).
There are a handful of half-decent web-based image editors out there that could potentially be integrated into an Odoo module, that could allow print shops to build a viable web-to-print shop for basics like t-shirts, business cards, company stationery and the like.
I think Odoo is the perfect platform for this type of functionality due to it's robust nature and extendability, and I anticipate that an extendable module/app achieving some basic web-to-print functionality (even just calculated fields and an upload facility for designs) would be in quite high demand if it was either a reasonably priced LGPL3 module, or a community module.
I thought this might be a useful reference for you if you're interested in in-browser editors for web-to-print:
https://www.drupal.org/project/imageeditor
@Luke, I won't go very far with this module though. I'll only extend the current sale.order module and add some of those fields to the webshop so the user has an extra page where he can choose/fill in details. So nothing to advanced but it will give other people inside in to the basics too :)