Skip to content

[10.0][ADD] Add website_portal_contract#62

Merged
lasley merged 4 commits into
OCA:10.0from
LasLabs:feature/10.0/LABS-356-create-website_portal_contract
Oct 9, 2017
Merged

[10.0][ADD] Add website_portal_contract#62
lasley merged 4 commits into
OCA:10.0from
LasLabs:feature/10.0/LABS-356-create-website_portal_contract

Conversation

@woodbrettm

@woodbrettm woodbrettm commented Apr 18, 2017

Copy link
Copy Markdown

Hi there,

This module adds website templates to contracts as well as the ability to view them in My Account.

TODO

  • Add printing to pdfs (from website view) to roadmap

Need Help

  • Finish controller tests. Can't seem to get a request going properly in tests. Not many fully tested controllers, so curious if anyone knows of any examples.
  • I think the controller should be separated into 2 classes, if anyone else agrees.
  • Go to My Account in website portal, Your Contracts, and then the contract. I think the way I have the Invoices & Balance table set up is incorrect in the view that comes up.
  • What does this line of js do? I'm using this js page to dynamically fill the sidenav with the headers, however I'm having some issues of what to name in the xml and how I should name the elements for the js to work.

Thanks!
Brett

@lasley

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch from bc4b43c to 31674b3 Compare April 18, 2017 05:30
@lasley

lasley commented Apr 26, 2017

Copy link
Copy Markdown
Contributor

@BMW95 what is your issue in the controller test? Did you try an HttpCase?

That JS selects some elements matching some selectors inside of this.spy_watched context, then updates their id to "". It then subsequently loops through any h1/h2 element in this.spy_watched, sets the IDs to specific things (to allow hotlinking to them), then creates an a element nested in an li linking to #id, then updating the text of the A to match the text of the header.

@rafaelbn rafaelbn added this to the 10.0 milestone May 6, 2017
@woodbrettm

Copy link
Copy Markdown
Author

@lasley thanks for the help. Got the JS issue fixed, however I'm still having issues with the tests, and also rendering a pdf report. Issues below:

Tests

======================================================================
 ERROR: test_account (odoo.addons.website_portal_contract.tests.test_website_account.TestWebsiteAccount)
 ` Test updates qcontext with contract count
 Traceback (most recent call last):
 `   File "/media/sf_odoo10dev/contract/website_portal_contract/tests/test_website_account.py", line 38, in test_account
 `     res = self.controller.account()
 `   File "/opt/odoo/odoo/http.py", line 504, in response_wrap
 `     response = f(*args, **kw)
 `   File "/media/sf_odoo10dev/contract/website_portal_contract/controllers/main.py", line 20, in account
 `     response = super(WebsiteAccount, self).account(**kw)
 `   File "/opt/odoo/odoo/http.py", line 504, in response_wrap
 `     response = f(*args, **kw)
 `   File "/opt/odoo/addons/website_portal_sale/controllers/main.py", line 16, in account
 `     response = super(website_account, self).account(**kw)
 `   File "/opt/odoo/odoo/http.py", line 504, in response_wrap
 `     response = f(*args, **kw)
 `   File "/opt/odoo/addons/website_portal/controllers/main.py", line 56, in account
 `     return request.render("website_portal.portal_my_home", values)
 `   File "/opt/odoo/_venv/local/lib/python2.7/site-packages/werkzeug/local.py", line 343, in __getattr__
 `     return getattr(self._get_current_object(), name)
 ` AttributeError: 'JsonRequest' object has no attribute 'render'
Ran 1 test in 0.011s

Reports

  • I'm having an issue with a model_name returning False in odoo's get_html method and I can't quite figure out why.
  • My report xml here
  • My controller code here
  • website_quote controller code I'm using as reference here
  • website_quote xml code here
Traceback (most recent call last):
  File "/opt/odoo/addons/website/models/ir_http.py", line 265, in _handle_exception
    response = super(Http, cls)._handle_exception(exception)
  File "/opt/odoo/odoo/addons/base/ir/ir_http.py", line 169, in _handle_exception
    return request._handle_exception(exception)
  File "/opt/odoo/odoo/http.py", line 766, in _handle_exception
    return super(HttpRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/addons/base/ir/ir_http.py", line 195, in _dispatch
    result = request.dispatch()
  File "/opt/odoo/odoo/http.py", line 825, in dispatch
    r = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 331, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 119, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 324, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 933, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 504, in response_wrap
    response = f(*args, **kw)
  File "/media/sf_odoo10dev/contract/website_portal_contract/controllers/main.py", line 74, in portal_contract
    data=None,
  File "/opt/odoo/addons/report/models/report.py", line 165, in get_pdf
    html = self.with_context(context).get_html(docids, report_name, data=data)
  File "/opt/odoo/addons/report/models/report.py", line 133, in get_html
    docs = self.env[report.model].browse(docids)
  File "/opt/odoo/odoo/api.py", line 752, in __getitem__
    return self.registry[model_name]._browse((), self)
  File "/opt/odoo/odoo/modules/registry.py", line 170, in __getitem__
    return self.models[model_name]
KeyError: False

@lasley

lasley commented May 15, 2017

Copy link
Copy Markdown
Contributor

@BMW95 with the controller, why not just use a tour to make sure that the rendered template contains what's needed? Look at this sample, making sure to set it up in Python and including the tour in assets when in demo mode

@lasley

lasley commented May 15, 2017

Copy link
Copy Markdown
Contributor

Regarding the report, why are you creating a PDF? This is a website based addon.

@woodbrettm

Copy link
Copy Markdown
Author

I was following what was being done in website_quote, which allows the customer to print their quotes from website to a pdf. Will remove that feature.

@lasley

lasley commented May 15, 2017

Copy link
Copy Markdown
Contributor

Let's add that to roadmap

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch 2 times, most recently from b91b562 to f6ae2a2 Compare May 23, 2017 04:29
{
content: 'Click on Your Contracts',
trigger: "a:contains('Your Contracts')",
},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasley so I built this tour for the js testing. This first step passes, however the next step fails I believe because it's a new url page.

I want the trigger to redirect the url to a new page, but not sure if this is the way to do that. Is this correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should perform the interactions to get to the page you need. How would the user do it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrmmm this doesn't make sense. Everything works fine now in my browser when I run the test, but it's not happy in travis.

One of the travis tests are passing currently, and when I pushed the last WIP commit, all the tests passed on the LasLabs side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something with the cross merge. Try rebasing onto current OCA/10.0 to at least if we can make the fail consistent across Travis

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch 12 times, most recently from b3ccf89 to b241ebf Compare May 31, 2017 17:16
@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch 4 times, most recently from c1d4a1c to 84d5ac5 Compare June 20, 2017 03:31
@woodbrettm

Copy link
Copy Markdown
Author

Updated!


def test_template_view(self):
""" It should respond with 200 status """
response = self.url_open('/contract/template/1')

@lasley lasley Sep 6, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not triggering the controller, which means you're likely throwing in a bad ID. Are you sure the template ID is 1? Why not use an env.ref().id instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. You're not logged in, so it's sending you to the login page.

self.authenticate('admin', 'admin')
self.url_open

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see interesting. The id in this case is definitely 1, but ye better idea to do ref.

I didn't realize you had to explicitly authenticate in this case, which solves my confusion as to why the method wasn't being covered.

@woodbrettm

Copy link
Copy Markdown
Author

Hmm. Everything seems to be passing except odoo/odoo travis.

@rafaelbn

rafaelbn commented Sep 7, 2017

Copy link
Copy Markdown
Member

Hey! I approved with travis 💚 😄

Review:

2017-09-06 22:42:02,817 4828 INFO openerp_test werkzeug: 127.0.0.1 - - [06/Sep/2017 22:42:02] "GET /contract/template/1 HTTP/1.1" 301 -

2017-09-06 22:42:12,864 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: ERROR

2017-09-06 22:42:12,881 4828 INFO openerp_test odoo.addons.website_portal_contract.tests.test_controller: ======================================================================

2017-09-06 22:42:12,882 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: ERROR: test_template_view (odoo.addons.website_portal_contract.tests.test_controller.TestController)

2017-09-06 22:42:12,882 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: ` It should respond with 200 status

2017-09-06 22:42:12,882 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: Traceback (most recent call last):

2017-09-06 22:42:12,883 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/home/travis/build/OCA/contract/website_portal_contract/tests/test_controller.py", line 31, in test_template_view

2017-09-06 22:42:12,883 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     '/contract/template/%d' % contract.id

2017-09-06 22:42:12,883 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/home/travis/odoo-10.0/odoo/tests/common.py", line 270, in url_open

2017-09-06 22:42:12,883 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     return self.opener.open(url, data, timeout)

2017-09-06 22:42:12,883 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 410, in open

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     response = meth(req, response)

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/home/travis/odoo-10.0/odoo/tests/common.py", line 228, in http_response

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     'http', request, response, code, msg, hdrs)

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 442, in error

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     result = self._call_chain(*args)

2017-09-06 22:42:12,884 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     result = func(*args)

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 629, in http_error_302

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     return self.parent.open(new, timeout=req.timeout)

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 404, in open

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     response = self._open(req, data)

2017-09-06 22:42:12,885 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 422, in _open

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     '_open', req)

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     result = func(*args)

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     return self.do_open(httplib.HTTPConnection, req)

2017-09-06 22:42:12,886 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/urllib2.py", line 1187, in do_open

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     r = h.getresponse(buffering=True)

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/httplib.py", line 1089, in getresponse

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     response.begin()

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/httplib.py", line 444, in begin

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     version, status, reason = self._read_status()

2017-09-06 22:42:12,887 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/httplib.py", line 400, in _read_status

2017-09-06 22:42:12,888 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     line = self.fp.readline(_MAXLINE + 1)

2017-09-06 22:42:12,888 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `   File "/usr/lib/python2.7/socket.py", line 476, in readline

2017-09-06 22:42:12,888 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: `     data = self._sock.recv(self._rbufsize)

2017-09-06 22:42:12,888 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: ` timeout: timed out

2017-09-06 22:42:12,888 4828 INFO openerp_test odoo.addons.website_portal_contract.tests.test_controller: Ran 2 tests in 25.193s

2017-09-06 22:42:12,889 4828 ERROR openerp_test odoo.addons.website_portal_contract.tests.test_controller: FAILED

2017-09-06 22:42:12,889 4828 INFO openerp_test odoo.addons.website_portal_contract.tests.test_controller:  (errors=1)

2017-09-06 22:42:12,890 4828 INFO openerp_test odoo.modules.module: odoo.addons.website_portal_contract.tests.test_controller tested in 25.20s, 2385 queries

2017-09-06 22:42:12,894 4828 ERROR openerp_test odoo.modules.module: Module website_portal_contract: 0 failures, 1 errors

2017-09-06 22:42:12,896 4828 INFO openerp_test odoo.modules.loading: All post-tested in 25.22s, 2385 queries

2017-09-06 22:42:12,899 4828 INFO openerp_test odoo.models: Computing parent left and right for table ir_ui_menu...

2017-09-06 22:42:12,993 4828 INFO openerp_test odoo.service.server: Initiating shutdown

2017-09-06 22:42:12,993 4828 INFO openerp_test odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

2017-09-06 22:42:13,000 4828 ERROR openerp_test odoo.addons.website.models.ir_http: 500 Internal Server Error:

Traceback (most recent call last):

@rafaelbn rafaelbn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for travis green

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch 5 times, most recently from 9bfabb0 to 60c64b3 Compare September 8, 2017 18:25
@woodbrettm

Copy link
Copy Markdown
Author

@rafaelbn I'm having some consistency issues with the builds. With the extra test in, all LasLabs builds were passing, runbot was passing, and the OCA/OCB build was passing here as well, however the Odoo/Odoo travis was posting the error you have commented, which seems to be that it's timing out. There was one time where it was passing, so not entirely sure what the issue is there.

I decided to remove the extra test if that's ok with you.

    def test_template_view(self):
        """ It should respond with 200 status """
        contract = self.env.ref(
            'website_portal_contract.'
            'website_contract_template_default'
        )
        self.authenticate('admin', 'admin')
        response = self.url_open(
            '/contract/template/%d' % contract.id
        )
        self.assertEquals(
            response.getcode(),
            200,
        )

@lasley

lasley commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

@BMW95 - that is an invalid URL. Have you attempted a URL open on the contract template slug instead of the ID?

image

@woodbrettm

Copy link
Copy Markdown
Author

Ah I understand now. All my xml href's are directly to the ID of the object, and thus it redirects. Didn't realize it she be like this and in the backend. I'll give that a try.

@lasley

lasley commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

Realistically you should still be receiving a 30x code (redirect), but something could be wonky with the internal test request or something. Never know

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch from 60c64b3 to 060a6ca Compare September 8, 2017 19:48
@lasley

lasley commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

Woot changing all the tests to HTTPCase worked! We can thank @sylvain-garancher for that one (OCA/report-print-send#95 (comment))

@woodbrettm woodbrettm force-pushed the feature/10.0/LABS-356-create-website_portal_contract branch 5 times, most recently from dab5bab to e074076 Compare September 8, 2017 23:02
@woodbrettm

Copy link
Copy Markdown
Author

Tests passing!

@lasley lasley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lasley

lasley commented Oct 5, 2017

Copy link
Copy Markdown
Contributor

@rafaelbn - have your comments been attended to?

@rafaelbn rafaelbn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 👍 . Please review if you can squash commits before merge

@lasley lasley merged commit bc4d08b into OCA:10.0 Oct 9, 2017
@lasley lasley deleted the feature/10.0/LABS-356-create-website_portal_contract branch October 9, 2017 15:21
victoralmau pushed a commit to Tecnativa/contract that referenced this pull request Jul 3, 2025
When calling _compute_payslip_line() call it on the payslip object and
not recordset 'self'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants