Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Add fields on webshop and send data to quotation order?

By
Yenthe
on 5/25/15, 10:44 AM 1,488 views

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 Branch
on 5/27/15, 4:22 AM

@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.

Yenthe
on 5/27/15, 7:21 AM

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)...

Jérémy Kersten (jke)
on 5/27/15, 11:37 AM

@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

Luke Branch
on 5/27/15, 11:46 AM

@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 Branch
on 5/27/15, 11:55 AM

@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
on 5/28/15, 10:25 AM

@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 Branch
on 5/29/15, 12:36 AM

@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
on 5/29/15, 7:09 AM

@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.

Luke Branch
on 5/30/15, 12:01 AM

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 Branch
on 5/30/15, 12:06 AM

@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 :)

Yenthe
on 5/30/15, 10:59 AM
2

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2983
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 5/27/15, 4:56 PM

I don't know if it will help you...

But if I have well understand your needs, it should...

https://github.com/JKE-be/quick-odoo/tree/extra_info_so_line_v8 


Ps: Hope that I see you to Odoo Experience :) (https://www.odoo.com/event/odoo-experience-304/track/how-to-customize-e-commerce-web-pages-424)



-- PART 2 --

For your question 1: Use checkbox...

Just using bootstrap: see here an example

https://github.com/JKE-be/quick-odoo/commit/454650d00676462980baceea1cba57b8f31f2c04 


For your question 2: Switch step...

Just changing xpath... But be aware, that you cannot easily change the href from a in /shop/car, because other view use it...

Maybe playing with sequence ? Else, I use a js hack to test now...

https://github.com/JKE-be/quick-odoo/commit/fee3984891d3060e39cf8c0074aabaa06b6694c5 


For you question 3: write on field

It should work... I have just tested with 'product_qty_uom' : 10 and it works... So check maybe your value, you have probably a typo in get param when you compute your new qty... print the value before ?


-- PART 3 --

I Fixed view order with a clean teplate (no js)

Like I said in part 2, play with sequence fix the problem...

See my commit https://github.com/JKE-be/quick-odoo/commit/a2fcb3c1981a375f380d8d918e4ce3efae3225c2


-- PART 4 --

See my commit https://github.com/JKE-be/quick-odoo/commit/bca808

It should work... info will be on sale order... 

ps: _prepare_order_line_invoice_line is only to prepare values to be write on Invoice...

Just a proto, need to be improved :)

Jérémy Kersten (jke)
on 5/27/15, 4:57 PM

Thanks Jérémy! I've both accepted & upvoted your answer. It doesn't do everything I need but gives me a very good insight how to continue / extend this! I have three questions that I hope you can answer. 1) How can I make fields in the webshop that are not digit? I tried with type="boolean" to get checkboxes for example but that simply gives me a textfield. 2) Would it be much work to change the flow from Review Order > Shipping & Billing > Extra to Review Order > Extra > Shipping & Billing? I think that makes more sense. 3) How exactly should I calculate and fill on field in the back-end with data from the webshop? I tried it like this: 'product_uom_qty': (int(post.get('%s-%s' % (line.id, 'hoogteWebshop'))) * int(post.get('%s-%s' % (line.id, 'breedteWebshop'))) / 10000 * 1 but the field product_uom_qty is not updated/calculated in the backend..

Yenthe
on 5/28/15, 10:31 AM

On a sidenote: yes I will be at Odoo Experience! You're free to come have a chat at our stand (VanRoey), you're always welcome there :) And I will attend that session for sure, I'm not used to the website part yet.

Yenthe
on 5/28/15, 10:35 AM

I have just updated my previous answer... See part 2 ! Have a good evening...

Jérémy Kersten (jke)
on 5/28/15, 4:56 PM

Hi Jérémy! Changing the order seems to be something you'd better don't do, seems to give some annoying problems.. so I'll leave that for what it is for now. The solution about checkboxes was really stupid, should've figured that one out by myself :) And for the calculation: I've got that working now too! There only rests me one question now.. I've created a new model (sale.order.line.colorpicker) which simply holds color names. All those names are filled in a dropdown on the quotation/sale order screen in the following field: kleurenpicker (this is a Many2one from sale.order to sale.order.line.colorpicker). This colorpicker should be shown on the extra screen but only once, above all the products, and this should then be passed from the webshop to the correct quotation / order.. any ideas? :s If you need more information or code let me know. And thanks a lot for all this help! I will soon try to create a blog post about such things to help others too :)

Yenthe
on 5/29/15, 5:54 AM

Hi for the step order, See part 3, I have fixed without JS the inherit... About your last point I have some doubts about what you are trying to do... I understand: "Only one color for one order", but the model name suggests an other thing "sale.order.line.colorpicker"... (and not sale.order.colorpicker)... So if you can provide the code, it will help me :)

Jérémy Kersten (jke)
on 5/29/15, 6:23 AM

@Jeremy I've updated my question to add more details and some of the code!

Yenthe
on 5/29/15, 7:06 AM

@yenthe, branch updated

Jérémy Kersten (jke)
on 5/29/15, 11:21 AM

Thanks again Jérémy! I've decided to share my whole module now so you can see what I have. The flow on the webshop should go like this: Review Order > Shipping & Billing > Extra > Payment > Confirmation. Or even better might be to leave Payment out. Could you tell me what I'm doing wrong or missing to make this flow work? Also, the selected color does not seem to show up on the order either :s Think you could have a look? Thanks for all the help.

Yenthe
on 5/30/15, 10:43 AM

See https://github.com/Yenthe666/Dev/tree/master/aa_houbolak

Yenthe
on 5/30/15, 10:50 AM

@yenthe, See your first pull request :) https://github.com/Yenthe666/Dev/pull/1/commits

Jérémy Kersten (jke)
on 5/30/15, 3:28 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

6 follower(s)

Stats

Asked: 5/25/15, 10:44 AM
Seen: 1488 times
Last updated: 5/30/15, 10:59 AM